not sure what it is exactly but with an external a...
# help
i
not sure what it is exactly but with an external auth provider (discord) the logins keep looping. i redirect back to the page i login from and it doesn't detect the login
n
Hello @ian_! This thread has been automatically created from your message in #843999948717555735 a few seconds ago. We have already mentioned the @User so that they can see your message and help you as soon as possible! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ``...`` menu) and select "Leave Thread" to unsubscribe from future updates. Want to change the title? Use the ``/title`` command! We have solved your problem? Click the button below to archive it.
i
says "couldn't get session from url" sometimes
Copy code
js
import type { ApiError, Session, User } from '@supabase/supabase-js'
import { toast } from '@zerodevx/svelte-toast'
import { supabase } from './supabase'
let authResult: {
    session?: Session
    user?: User
    error?: ApiError
}
window.supabase = supabase
console.log(supabase.auth.user() ? 'logged in' : 'not logged in')
await new Promise<void>((resolve, reject) => {
    console.log('waiting for load')
    if (document.readyState === 'complete') resolve()
    window.addEventListener('load', () => resolve())
})
console.log('loaded', document.readyState)
if (supabase.auth.user() === null && !window.location.pathname.includes('#')) {
    console.log('logging in...')
    authResult = await supabase.auth.signIn({
        provider: 'discord'
    },
        {
            redirectTo: window.location.href
        }
    )
    if (authResult.error) toast.push(`Login failed, try reloading: ${authResult.error.message}`)
} else {
    console.log('already logged in')
    authResult = { user: supabase.auth.user(), session: supabase.auth.session() }
}
const { user, session } = authResult
const identity = user ? user.identities[0] : null
console.log(authResult)
export { supabase, user, session, identity }