feat: integrate Firebase for authentication and data management, add GameItem type, and enhance UI with tooltips
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user