@@ -7,9 +7,6 @@ type User = { email: string } | null;
77type AuthCtx = {
88 user : User ;
99 token : string | null ;
10- signIn : ( email : string , password : string ) => Promise < void > ;
11- signUp : ( email : string , password : string ) => Promise < void > ;
12- signOut : ( ) => void ;
1310 authHeader : ( ) => Record < string , string > ;
1411} ;
1512
@@ -23,42 +20,8 @@ export function AuthProvider({ children }: { children: ReactNode }) {
2320
2421 const authHeader = ( ) => ( token ? { Authorization : `Bearer ${ token } ` } : { } ) ;
2522
26- async function signIn ( email : string , password : string ) {
27- const res = await fetch ( `${ API_BASE } /auth/signin` , {
28- method : "POST" ,
29- headers : { "Content-Type" : "application/json" } ,
30- body : JSON . stringify ( { email, password } )
31- } ) ;
32- if ( ! res . ok ) {
33- const msg = ( await res . json ( ) . catch ( ( ) => ( { } as any ) ) ) ?. detail || "Sign in failed" ;
34- throw new Error ( String ( msg ) ) ;
35- }
36- const data = await res . json ( ) ;
37- setToken ( data . access_token ) ;
38- setUser ( { email } ) ;
39- }
40-
41- async function signUp ( email : string , password : string ) {
42- const res = await fetch ( `${ API_BASE } /auth/signup` , {
43- method : "POST" ,
44- headers : { "Content-Type" : "application/json" } ,
45- body : JSON . stringify ( { email, password } )
46- } ) ;
47- if ( ! res . ok ) {
48- const msg = ( await res . json ( ) . catch ( ( ) => ( { } as any ) ) ) ?. detail || "Sign up failed" ;
49- throw new Error ( String ( msg ) ) ;
50- }
51- // auto sign-in after sign-up
52- await signIn ( email , password ) ;
53- }
54-
55- function signOut ( ) {
56- setToken ( null ) ;
57- setUser ( null ) ;
58- }
59-
6023 return (
61- < AuthContext . Provider value = { { user, token, signIn , signUp , signOut , authHeader } } >
24+ < AuthContext . Provider value = { { user, token, authHeader } } >
6225 { children }
6326 </ AuthContext . Provider >
6427 ) ;
0 commit comments