File tree Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Original file line number Diff line number Diff line change
1
+ import supabase from '../createClient' ;
2
+
3
+ /**
4
+ * Checks if the current email is already tied to a user account.
5
+ * @returns a Promise of whether the email is already in use
6
+ */
7
+ export async function checkEmailExists ( email : string ) : Promise < boolean > {
8
+ const { data, error } = await supabase . rpc ( 'check_email_exists' , {
9
+ p_email : email ,
10
+ } ) ;
11
+
12
+ if ( error ) {
13
+ throw new Error ( `Error checking email existence: ${ error . message } ` ) ;
14
+ }
15
+
16
+ return data ;
17
+ }
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import {
11
11
import { AuthError , AuthResponse , Session } from '@supabase/supabase-js' ;
12
12
import type { UUID } from 'crypto' ;
13
13
import supabase from '@/api/supabase/createClient' ;
14
+ import { checkEmailExists } from '@/api/supabase/queries/email' ;
14
15
15
16
export interface AuthContextType {
16
17
session ?: Session ;
@@ -104,11 +105,7 @@ export default function AuthProvider({
104
105
// This code is largely taken from https://github.com/orgs/supabase/discussions/1282#discussioncomment-5230475
105
106
106
107
// User exists, but is fake. See https://supabase.com/docs/reference/javascript/auth-signup
107
- if (
108
- value . data . user &&
109
- value . data . user . identities &&
110
- value . data . user . identities . length === 0
111
- ) {
108
+ if ( await checkEmailExists ( email ) ) {
112
109
const authError = new AuthError (
113
110
'A user account with this email already exists' ,
114
111
) ;
You can’t perform that action at this time.
0 commit comments