diff --git a/app/(auth)/login/page.tsx b/app/(auth)/login/page.tsx index 2f11bacd..5b373dad 100644 --- a/app/(auth)/login/page.tsx +++ b/app/(auth)/login/page.tsx @@ -74,6 +74,29 @@ export default function LoginPage() { return } + // Check for pending invite token + const bankIdCookieMatch = document.cookie.match(/gnubok-invite-token=([^;]+)/) + const bankIdInviteToken = bankIdCookieMatch?.[1] + + if (bankIdInviteToken) { + try { + const res = await fetch('/api/team/accept', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ token: bankIdInviteToken }), + }) + + if (res.ok) { + document.cookie = 'gnubok-invite-token=; path=/; max-age=0' + window.location.href = '/' + return + } + } catch (err) { + console.error('[login] invite acceptance failed:', err) + } + document.cookie = 'gnubok-invite-token=; path=/; max-age=0' + } + router.push('/') router.refresh() } catch (error) { @@ -120,6 +143,30 @@ export default function LoginPage() { return } + // Check for pending invite token + const cookieMatch = document.cookie.match(/gnubok-invite-token=([^;]+)/) + const inviteToken = cookieMatch?.[1] + + if (inviteToken) { + try { + const res = await fetch('/api/team/accept', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ token: inviteToken }), + }) + + if (res.ok) { + document.cookie = 'gnubok-invite-token=; path=/; max-age=0' + window.location.href = '/' + return + } + } catch (err) { + console.error('[login] invite acceptance failed:', err) + } + // Clear cookie even on failure to avoid retrying stale tokens + document.cookie = 'gnubok-invite-token=; path=/; max-age=0' + } + router.push('/') router.refresh() } catch (error) { diff --git a/app/(auth)/mfa/verify/page.tsx b/app/(auth)/mfa/verify/page.tsx index 1e4789d6..876ef442 100644 --- a/app/(auth)/mfa/verify/page.tsx +++ b/app/(auth)/mfa/verify/page.tsx @@ -100,6 +100,29 @@ export default function MfaVerifyPage() { return } + // Check for pending invite token + const cookieMatch = document.cookie.match(/gnubok-invite-token=([^;]+)/) + const inviteToken = cookieMatch?.[1] + + if (inviteToken) { + try { + const res = await fetch('/api/team/accept', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ token: inviteToken }), + }) + + if (res.ok) { + document.cookie = 'gnubok-invite-token=; path=/; max-age=0' + window.location.href = '/' + return + } + } catch (err) { + console.error('[mfa/verify] invite acceptance failed:', err) + } + document.cookie = 'gnubok-invite-token=; path=/; max-age=0' + } + router.push('/') router.refresh() } catch { diff --git a/app/invite/[token]/page.tsx b/app/invite/[token]/page.tsx index 9ef51fb9..cbe1f219 100644 --- a/app/invite/[token]/page.tsx +++ b/app/invite/[token]/page.tsx @@ -46,12 +46,20 @@ export default function InvitePage() { loadInvite() }, [token]) + const secureCookieFlag = typeof window !== 'undefined' && window.location.protocol === 'https:' ? '; secure' : '' + const handleAccept = () => { // Store invite token in cookie before redirecting to register - document.cookie = `gnubok-invite-token=${token}; path=/; max-age=3600; samesite=lax` + document.cookie = `gnubok-invite-token=${token}; path=/; max-age=3600; samesite=lax${secureCookieFlag}` router.push(`/register?invite=${encodeURIComponent(token)}`) } + const handleAcceptExistingUser = () => { + // Store invite token in cookie before redirecting to login + document.cookie = `gnubok-invite-token=${token}; path=/; max-age=3600; samesite=lax${secureCookieFlag}` + router.push('/login') + } + if (isLoading) { return (
E-postadressen har redan ett konto
-- {invite.email} är redan registrerad på gnubok. - Kontot måste tas bort innan du kan acceptera inbjudan. -
- - Gå till inloggning - +{invite.companyName}
++ Du har bjudits in som medlem till detta företag. +
++ {invite.email} har redan ett konto på gnubok. + Logga in för att gå med. +
+