summaryrefslogtreecommitdiff
path: root/lib/auth.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'lib/auth.tsx')
-rw-r--r--lib/auth.tsx25
1 files changed, 19 insertions, 6 deletions
diff --git a/lib/auth.tsx b/lib/auth.tsx
index b05c6a7..ac394f4 100644
--- a/lib/auth.tsx
+++ b/lib/auth.tsx
@@ -1,9 +1,9 @@
import {
- createContext,
- ReactNode,
- useContext,
- useEffect,
- useState,
+ createContext,
+ ReactNode,
+ useContext,
+ useEffect,
+ useState,
} from "react";
import { apiClient } from "../api/client";
@@ -17,6 +17,9 @@ type AuthContextType = AuthState & {
email: string,
password: string,
) => Promise<{ success: boolean; reason?: string }>;
+ signInWithGoogle: (
+ idToken: string,
+ ) => Promise<{ success: boolean; reason?: string }>;
signUp: (
email: string,
password: string,
@@ -60,13 +63,23 @@ export function AuthProvider({ children }: { children: ReactNode }) {
return { success: result.success, reason: result.reason };
};
+ const signInWithGoogle = async (idToken: string) => {
+ const result = await apiClient.signInWithGoogle(idToken);
+ if (result.success) {
+ setState({ isLoading: false, isAuthenticated: true });
+ }
+ return { success: result.success, reason: result.reason };
+ };
+
const signOut = async () => {
await apiClient.signOut();
setState({ isLoading: false, isAuthenticated: false });
};
return (
- <AuthContext.Provider value={{ ...state, signIn, signUp, signOut }}>
+ <AuthContext.Provider
+ value={{ ...state, signIn, signInWithGoogle, signUp, signOut }}
+ >
{children}
</AuthContext.Provider>
);