Deimos
Deimos
Explore posts from servers
SSolidJS
Created by Deimos on 5/24/2024 in #support
How do I redirect properly?
"use server";

import {
GoogleAuthProvider,
signInAnonymously,
signInWithPopup,
} from "firebase/auth";
import { auth } from "./client-firebase";
import { createUserSession } from "./session";
import { redirect } from "@solidjs/router";

const googleProvider = new GoogleAuthProvider();

export const signInWithGoogle = async () => {
try {
const userCredential = await signInWithPopup(auth, googleProvider);
console.log("Signed in with Google:", userCredential.user);

const token = await userCredential.user.getIdToken();
await createUserSession(token);
} catch (error) {
console.error("Error signing in with Google:", error);
throw error;
}
};

export const signInAsAGuest = async (event) => {
try {
const userCredential = await signInAnonymously(auth);
const token = await userCredential.user.getIdToken();
const user = await createUserSession(token);
if (user) throw redirect("/in");
} catch (error) {
console.error("Error signing in as guest:", error);
throw error;
}
};
"use server";

import {
GoogleAuthProvider,
signInAnonymously,
signInWithPopup,
} from "firebase/auth";
import { auth } from "./client-firebase";
import { createUserSession } from "./session";
import { redirect } from "@solidjs/router";

const googleProvider = new GoogleAuthProvider();

export const signInWithGoogle = async () => {
try {
const userCredential = await signInWithPopup(auth, googleProvider);
console.log("Signed in with Google:", userCredential.user);

const token = await userCredential.user.getIdToken();
await createUserSession(token);
} catch (error) {
console.error("Error signing in with Google:", error);
throw error;
}
};

export const signInAsAGuest = async (event) => {
try {
const userCredential = await signInAnonymously(auth);
const token = await userCredential.user.getIdToken();
const user = await createUserSession(token);
if (user) throw redirect("/in");
} catch (error) {
console.error("Error signing in as guest:", error);
throw error;
}
};
redirect raises an error, Error signing in as guest: Response {
status: 302, statusText: '', headers: Headers { location: '/in' }, body: null, bodyUsed: false, ok: false, redirected: false, type: 'default', url: '' }
24 replies
SSolidJS
Created by Deimos on 5/24/2024 in #support
Empty Password while updating session.
import { createAsync } from "@solidjs/router";
import { updateSession, useSession } from "vinxi/http";

const sessionConfig = {
password: import.meta.env.VITE_SESSION_SECRET,
};

export async function getSession(event) {
'use server'
return await useSession(event, sessionConfig);
}

export async function createUserSession(event, token) {
'use server'
const session = await updateSession(event, sessionConfig, {
token: token
})

return session;
}
import { createAsync } from "@solidjs/router";
import { updateSession, useSession } from "vinxi/http";

const sessionConfig = {
password: import.meta.env.VITE_SESSION_SECRET,
};

export async function getSession(event) {
'use server'
return await useSession(event, sessionConfig);
}

export async function createUserSession(event, token) {
'use server'
const session = await updateSession(event, sessionConfig, {
token: token
})

return session;
}
There is password in session config and it is not empty but it keeps saying Empty password. The error is Error: Empty password at seal (file:///E:/Projects/24FM/node_modules/.pnpm/[email protected]/node_modules/iron-webcrypto/dist/index.js:222:11) at sealSession (file:///E:/Projects/24FM/node_modules/.pnpm/[email protected]/node_modules/h3/dist/index.mjs:1381:24) at updateSession (file:///E:/Projects/24FM/node_modules/.pnpm/[email protected]/node_modules/h3/dist/index.mjs:1369:26) at getSession (file:///E:/Projects/24FM/node_modules/.pnpm/[email protected]/node_modules/h3/dist/index.mjs:1355:11) at async updateSession (file:///E:/Projects/24FM/node_modules/.pnpm/[email protected]/node_modules/h3/dist/index.mjs:1361:60) at async Module.$$function1 (E:/Projects/24FM/src/lib/session.js:21:19) at async eval (E:/Projects/24FM/src/lib/auth.js:32:18) Why is that? Please help me :"(
3 replies
SSolidJS
Created by Deimos on 5/23/2024 in #support
Problem importing useSession from vinxi/http
I'm currently working on SolidStart with Firebase auth. The problem is whenever I try to use useSession() it raises an error saying Error: Module "node:async_hooks" has been externalized for browser compatibility. Cannot access "node:async_hooks.AsyncLocalStorage" in client code. See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
import {
GoogleAuthProvider,
signInAnonymously,
signInWithPopup,
} from "firebase/auth";
import { auth } from "./client-firebase";
import { useSession } from "vinxi/http";

const googleProvider = new GoogleAuthProvider();

export const signInWithGoogle = async () => {
try {
const userCredential = await signInWithPopup(auth, googleProvider);
console.log("Signed in with Google:", userCredential.user);

// Create user session and store session data
const token = userCredential.user.getIdToken();
} catch (error) {
console.error("Error signing in with Google:", error);
throw error;
}
};

export const signInAsAGuest = async () => {
try {
const userCredential = await signInAnonymously(auth);
console.log("Signed in as guest:", userCredential.user);

// Create user session and store session data
const token = userCredential.user.getIdToken();
const session = await useSession({
password: import.meta.env.SESSION_SECRET,
})

} catch (error) {
console.error("Error signing in as guest:", error);
throw error;
}
};
import {
GoogleAuthProvider,
signInAnonymously,
signInWithPopup,
} from "firebase/auth";
import { auth } from "./client-firebase";
import { useSession } from "vinxi/http";

const googleProvider = new GoogleAuthProvider();

export const signInWithGoogle = async () => {
try {
const userCredential = await signInWithPopup(auth, googleProvider);
console.log("Signed in with Google:", userCredential.user);

// Create user session and store session data
const token = userCredential.user.getIdToken();
} catch (error) {
console.error("Error signing in with Google:", error);
throw error;
}
};

export const signInAsAGuest = async () => {
try {
const userCredential = await signInAnonymously(auth);
console.log("Signed in as guest:", userCredential.user);

// Create user session and store session data
const token = userCredential.user.getIdToken();
const session = await useSession({
password: import.meta.env.SESSION_SECRET,
})

} catch (error) {
console.error("Error signing in as guest:", error);
throw error;
}
};
3 replies
TTCTheo's Typesafe Cult
Created by Deimos on 1/18/2024 in #questions
Nextjs 14 App Router fetch data as the searchParams change
I use App router in Nextjs 14. I'm having a problem fetching my data from page component as I change the searchParams in client component using params.set and params.delete. It is causing Hydration error. Can somebody guide me?
3 replies