Skip to content

Commit

Permalink
hopefully nothing blows up
Browse files Browse the repository at this point in the history
  • Loading branch information
philipye314 committed Apr 21, 2024
1 parent ee1ff21 commit 6516051
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/app/(Authentication)/Login/Password/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function LoginScreen() {
};

async function signIn() {
const { error } = await sessionHandler.signInWithEmail(email, password);
const error = await sessionHandler.signInWithEmail(email, password);
console.log(error);
if (error != null) {
setErrorExists(true);
Expand Down
5 changes: 3 additions & 2 deletions src/app/(Authentication)/OTPFlow/OTPVerify/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ export default function OTPFlow() {
};

const verifyToken = async (token: string) => {
const { error } = await verifyOtp(email, token);
if (error) {
const err = await verifyOtp(email, token);
console.log(err);
if (err.message) {
setErrorExists(true);
setErrorMessage('Sorry! The verification code was incorrect.');
return;
Expand Down
66 changes: 45 additions & 21 deletions src/context/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface AuthState {
password: string,
options: object,
) => Promise<AuthResponse>;
signInWithEmail: (email: string, password: string) => Promise<AuthResponse>;
signInWithEmail: (email: string, password: string) => Promise<AuthError>;
fullySignUpUser: (
fullName: string,
email: string,
Expand All @@ -46,7 +46,7 @@ export interface AuthState {
zip: string,
) => Promise<UserResponse>;
sendOtp: (email: string) => Promise<AuthResponse>;
verifyOtp: (email: string, token: string) => Promise<AuthResponse>;
verifyOtp: (email: string, token: string) => Promise<AuthError>;
resendOtp: (email: string) => Promise<AuthResponse>;
updateUser: (attributes: UserAttributes) => Promise<UserResponse>;
resetPassword: (email: string) => Promise<
Expand Down Expand Up @@ -102,12 +102,20 @@ export function AuthContextProvider({
};

const signInWithEmail = async (email: string, password: string) => {
const value = await supabase.auth.signInWithPassword({
email,
password,
}); // will trigger the use effect to update the session
setUser(value.data.user);
return value;
try {
const value = await supabase.auth.signInWithPassword({
email,
password,
}); // will trigger the use effect to update the session
if (value.error) {
throw value.error;
}
setUser(value.data.user);
return null;
} catch (error) {
console.warn(error);
return error;
}
};

const signUp = async (email: string, password: string, metaData: object) => {
Expand Down Expand Up @@ -154,11 +162,14 @@ export function AuthContextProvider({
fullName,
});
}
if (value.error) {
throw value.error;
}
return value;
} catch (error) {
// eslint-disable-next-line no-console
console.error('(signUpUser)', error);
throw error;
return error;
}
};

Expand All @@ -170,33 +181,46 @@ export function AuthContextProvider({

const sendOtp = async (email: string) => {
try {
return await supabase.auth.signInWithOtp({ email });
const value = await supabase.auth.signInWithOtp({ email });
if (value.error) {
throw value.error;
}
return value;
} catch (error) {
console.warn('there was an error sending your one time passcode');
throw error;
return error;
}
};

const verifyOtp = async (email: string, token: string) => {
const value = await supabase.auth.verifyOtp({
email,
token,
type: 'email',
});

// if (value.data.user) setUser(value.data.user);
return value;
try {
const value = await supabase.auth.verifyOtp({
email,
token,
type: 'email',
});
if (value.error) {
throw value.error;
}
return null;
} catch (error) {
console.warn('otp not working uh oh');
return error;
}
};

const resendOtp = async (email: string) => {
try {
return await supabase.auth.resend({
const value = await supabase.auth.resend({
type: 'signup',
email,
});
if (value.error) {
return value.error;
}
} catch (error) {
console.warn('there was an error resending your one time passcode');
throw error;
return error;
}
};

Expand Down

0 comments on commit 6516051

Please sign in to comment.