@@ -8,20 +8,24 @@ import type { LayoutLoad } from './$types';
88import { redirectTo } from './store' ;
99import { resolve } from '$app/paths' ;
1010import type { Account } from '$lib/stores/user' ;
11- import { AppwriteException , Platform } from '@appwrite.io/console' ;
11+ import { AppwriteException , Platform , type Models } from '@appwrite.io/console' ;
1212import { isCloud } from '$lib/system' ;
1313import { checkPricingRefAndRedirect } from '$lib/helpers/pricingRedirect' ;
1414import { getTeamOrOrganizationList } from '$lib/stores/organization' ;
1515import { makePlansMap } from '$lib/helpers/billing' ;
1616import { plansInfo as plansInfoStore } from '$lib/stores/billing' ;
17- import { isEmailVerificationRequiredError } from '$lib/helpers/emailVerification' ;
17+ import { isVerifyEmailRedirectError } from '$lib/helpers/emailVerification' ;
1818
1919export const ssr = false ;
2020
21+ const EMPTY_ORGANIZATIONS : Models . TeamList = { total : 0 , teams : [ ] } ;
22+
2123export const load : LayoutLoad = async ( { depends, url, route } ) => {
2224 depends ( Dependencies . ACCOUNT ) ;
2325 depends ( Dependencies . ORGANIZATIONS ) ;
2426
27+ const verifyEmailPath = resolve ( '/verify-email' ) ;
28+
2529 const [ account , error ] = ( await sdk . forConsole . account
2630 . get ( )
2731 . then ( ( response ) => [ response , null ] )
@@ -33,6 +37,18 @@ export const load: LayoutLoad = async ({ depends, url, route }) => {
3337 }
3438
3539 if ( account ) {
40+ // `/v1/teams` (and org list on cloud) returns 401 until the console account is verified;
41+ // do not call that API on this route while still unverified.
42+ if ( url . pathname === verifyEmailPath && ! account . emailVerification ) {
43+ const plansInfo = await getPlatformPlans ( ) ;
44+ plansInfoStore . set ( plansInfo ) ;
45+ return {
46+ plansInfo,
47+ account,
48+ organizations : EMPTY_ORGANIZATIONS
49+ } ;
50+ }
51+
3652 try {
3753 const [ plansInfo , organizations ] = await Promise . all ( [
3854 getPlatformPlans ( ) ,
@@ -47,15 +63,19 @@ export const load: LayoutLoad = async ({ depends, url, route }) => {
4763 organizations
4864 } ;
4965 } catch ( error ) {
50- if (
51- error instanceof AppwriteException &&
52- isEmailVerificationRequiredError ( error . type )
53- ) {
54- const verifyEmailUrl = resolve ( '/verify-email' ) ;
55-
56- if ( url . pathname !== verifyEmailUrl ) {
57- redirect ( 303 , withParams ( verifyEmailUrl , url . searchParams ) ) ;
66+ if ( isVerifyEmailRedirectError ( error ) ) {
67+ if ( url . pathname !== verifyEmailPath ) {
68+ redirect ( 303 , withParams ( verifyEmailPath , url . searchParams ) ) ;
5869 }
70+
71+ // Already on verify-email: do not rethrow; the teams API is blocked until verified.
72+ const plansInfo = await getPlatformPlans ( ) ;
73+ plansInfoStore . set ( plansInfo ) ;
74+ return {
75+ plansInfo,
76+ account,
77+ organizations : EMPTY_ORGANIZATIONS
78+ } ;
5979 }
6080
6181 throw error ;
@@ -77,11 +97,9 @@ export const load: LayoutLoad = async ({ depends, url, route }) => {
7797 redirect ( 303 , withParams ( mfaUrl , url . searchParams ) ) ;
7898 }
7999
80- if ( isEmailVerificationRequiredError ( error . type ) ) {
81- const verifyEmailUrl = resolve ( '/verify-email' ) ;
82-
83- if ( url . pathname !== verifyEmailUrl ) {
84- redirect ( 303 , withParams ( verifyEmailUrl , url . searchParams ) ) ;
100+ if ( isVerifyEmailRedirectError ( error ) ) {
101+ if ( url . pathname !== verifyEmailPath ) {
102+ redirect ( 303 , withParams ( verifyEmailPath , url . searchParams ) ) ;
85103 }
86104 }
87105
0 commit comments