mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
This PR runs `prettier` on the `examples` folder. Depends on https://github.com/supabase/supabase/pull/43849.
91 lines
1.7 KiB
TypeScript
91 lines
1.7 KiB
TypeScript
import { AuthProvider } from '@refinedev/core'
|
|
|
|
import { supabaseClient } from './utility'
|
|
|
|
const authProvider: AuthProvider = {
|
|
login: async ({ email }) => {
|
|
try {
|
|
const { error } = await supabaseClient.auth.signInWithOtp({ email })
|
|
|
|
if (!error) {
|
|
alert('Check your email for the login link!')
|
|
return {
|
|
success: true,
|
|
}
|
|
}
|
|
|
|
throw error
|
|
} catch (e: any) {
|
|
alert(e.message)
|
|
return {
|
|
success: false,
|
|
e,
|
|
}
|
|
}
|
|
},
|
|
logout: async () => {
|
|
const { error } = await supabaseClient.auth.signOut()
|
|
|
|
if (error) {
|
|
return {
|
|
success: false,
|
|
error,
|
|
}
|
|
}
|
|
|
|
return {
|
|
success: true,
|
|
redirectTo: '/',
|
|
}
|
|
},
|
|
onError: async (error) => {
|
|
console.error(error)
|
|
return { error }
|
|
},
|
|
check: async () => {
|
|
try {
|
|
const { data, error } = await supabaseClient.auth.getClaims()
|
|
|
|
if (error || !data) {
|
|
return {
|
|
authenticated: false,
|
|
error: {
|
|
message: 'Check failed',
|
|
name: 'Session not found',
|
|
},
|
|
logout: true,
|
|
redirectTo: '/login',
|
|
}
|
|
}
|
|
} catch (error: any) {
|
|
return {
|
|
authenticated: false,
|
|
error: error || {
|
|
message: 'Check failed',
|
|
name: 'Not authenticated',
|
|
},
|
|
logout: true,
|
|
redirectTo: '/login',
|
|
}
|
|
}
|
|
|
|
return {
|
|
authenticated: true,
|
|
}
|
|
},
|
|
getIdentity: async () => {
|
|
const { data } = await supabaseClient.auth.getUser()
|
|
|
|
if (data?.user) {
|
|
return {
|
|
...data.user,
|
|
name: data.user.email,
|
|
}
|
|
}
|
|
|
|
return null
|
|
},
|
|
}
|
|
|
|
export default authProvider
|