feat: integrate Firebase for authentication and data management, add GameItem type, and enhance UI with tooltips

This commit is contained in:
2025-02-15 21:54:28 -03:00
parent 62634a426e
commit a12cfc5a2a
17 changed files with 1498 additions and 28 deletions
+40
View File
@@ -0,0 +1,40 @@
import {
signInWithEmailAndPassword,
createUserWithEmailAndPassword,
signOut as firebaseSignOut,
User,
GoogleAuthProvider,
signInWithPopup
} from 'firebase/auth';
import { auth } from '../../config/firebase';
export async function login(email: string, password: string): Promise<string> {
const userCredential = await signInWithEmailAndPassword(auth, email, password);
const token = await userCredential.user.getIdToken();
localStorage.setItem('TOKEN', token);
return token;
}
export async function register(email: string, password: string): Promise<string> {
const userCredential = await createUserWithEmailAndPassword(auth, email, password);
const token = await userCredential.user.getIdToken();
localStorage.setItem('TOKEN', token);
return token;
}
export async function signOut(): Promise<void> {
await firebaseSignOut(auth);
localStorage.removeItem('TOKEN');
}
export function getCurrentUser(): User | null {
return auth.currentUser;
}
export async function signInWithGoogle(): Promise<string> {
const provider = new GoogleAuthProvider();
const userCredential = await signInWithPopup(auth, provider);
const token = await userCredential.user.getIdToken();
localStorage.setItem('TOKEN', token);
return token;
}