Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/components/OnboardingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ export default function OnboardingPage() {

if (session?.user?.email) {
handleSessionEstablished(session.user.email)
} else if (session?.user && !session.user.email) {
// Session exists but email is missing - clear the bad state
console.error('Auth state change: Session without email detected', session.user)
setValue('email', '')
setEmailLocked(false)
void supabase.auth.signOut() // Clear the problematic session
Comment on lines +98 to +102
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The logic here to handle a session without an email is inconsistent with the similar logic in checkSession (lines 126-140). This implementation is missing a user-facing notification (toast) and doesn't update the isCheckingAuth state, which could leave the UI in a loading state or cause confusion for the user.

To ensure consistent behavior, this block should also show a toast message and set isCheckingAuth to false. For better maintainability, consider refactoring this duplicated logic into a single helper function.

        // Session exists but email is missing - clear the bad state
        console.error('Auth state change: Session without email detected', session.user)
        setValue('email', '')
        setEmailLocked(false)
        setIsCheckingAuth(false)
        toast({
          variant: 'destructive',
          title: 'Authentication Issue',
          description: 'Your session is missing email information. Please try signing in again.'
        })
        void supabase.auth.signOut() // Clear the problematic session

} else if (session === null) {
// Clear email if user signs out (e.g., in another tab)
setValue('email', '')
Expand All @@ -117,6 +123,20 @@ export default function OnboardingPage() {

if (session?.user?.email) {
handleSessionEstablished(session.user.email)
} else if (session?.user && !session.user.email) {
// Session exists but email is missing - this is an error state
console.error('Session found but email is missing:', session.user)
if (isMounted) {
setEmailLocked(false) // Ensure field is not locked
setIsCheckingAuth(false)
toast({
variant: 'destructive',
title: 'Authentication Issue',
description: 'Your session is missing email information. Please try signing in again.'
})
// Clear the problematic session
void supabase.auth.signOut()
}
} else {
// No session found, set timeout to allow for magic link processing
timeoutId = setTimeout(() => {
Expand Down Expand Up @@ -318,6 +338,11 @@ export default function OnboardingPage() {
<Label htmlFor='email'>Email</Label>
<Input
id='email'
type='email'
autoComplete='email'
autoCapitalize='none'
autoCorrect='off'
spellCheck='false'
{...register('email', {
required: 'Email is required',
pattern: {
Expand Down Expand Up @@ -374,6 +399,11 @@ export default function OnboardingPage() {
Sign in with Google
</Button>
</form>
{debugInfo && (
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The debugInfo variable is used in the JSX but isn’t defined in this diff. Ensure that debug mode logic (e.g., reading ?debug=true) sets and passes debugInfo appropriately.

<div className='mt-4 p-2 bg-gray-100 rounded text-xs font-mono whitespace-pre-wrap'>
Debug Info:{debugInfo}
</div>
)}
Comment on lines +402 to +406
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The variable debugInfo is used here but it is not defined anywhere in the component. This will cause a ReferenceError at runtime and break the page. Please ensure debugInfo is declared and populated with the intended debug information, likely from a URL query parameter as mentioned in the pull request description.

</CardContent>
</Card>
</div>
Expand Down