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;
}
};