S
SolidJS6mo ago
Deimos

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;
}
};
Vite
Next Generation Frontend Tooling
2 Replies
Costinha
Costinha6mo ago
i had the same issue, i solved it calling "useSession()" inside a function server action notaded with "use server"
No description
Deimos
DeimosOP6mo ago
Thank you it worked!
Want results from more Discord servers?
Add your server