frontend/hooks/useLoginWithProvider.ts (view raw)
1const useLoginWithProvider = () => {
2 const setToken = () => {}; // DEV
3 const setUser = () => {}; // DEV
4
5 const loginWithProvider = async (provider: string, search: string) => {
6 const resultRaw = await fetch(`/api/auth/${provider}/callback${search}`);
7 const result = await resultRaw.json();
8 if (result.hasOwnProperty('error')) throw result;
9 setToken(result.jwt);
10 setUser(result.user);
11 return result;
12 };
13
14 return {loginWithProvider};
15};
16
17export default useLoginWithProvider;