Skip to content

Commit

Permalink
fix: tweak supertokens settings
Browse files Browse the repository at this point in the history
  • Loading branch information
exKAZUu committed Sep 18, 2024
1 parent 1809968 commit cce35a1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/app/auth/[[...path]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { NextPage } from 'next';
import { useEffect, useState } from 'react';
import { redirectToAuth } from 'supertokens-auth-react';
import { EmailPasswordPreBuiltUI } from 'supertokens-auth-react/recipe/emailpassword/prebuiltui';
import { EmailVerificationPreBuiltUI } from 'supertokens-auth-react/recipe/emailverification/prebuiltui';
import SuperTokens from 'supertokens-auth-react/ui';

import { clearAllCaches } from '../../../asyncFunctions/cache/actions';
Expand All @@ -16,15 +17,15 @@ const AuthPage: NextPage = () => {
// サインイン/アップに伴う画面表示の変更を反映するために、全ページのキャッシュを削除する。
void clearAllCaches();

if (SuperTokens.canHandleRoute([EmailPasswordPreBuiltUI])) {
if (SuperTokens.canHandleRoute([EmailPasswordPreBuiltUI, EmailVerificationPreBuiltUI])) {
setLoaded(true);
} else {
void redirectToAuth({ redirectBack: false });
}
}, []);

if (loaded) {
return SuperTokens.getRoutingComponent([EmailPasswordPreBuiltUI]);
return SuperTokens.getRoutingComponent([EmailPasswordPreBuiltUI, EmailVerificationPreBuiltUI]);
}
};

Expand Down
4 changes: 4 additions & 0 deletions src/infrastructures/supertokens/backendConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import SuperTokens from 'supertokens-node';
import DashboardNode from 'supertokens-node/recipe/dashboard';
import EmailPasswordNode from 'supertokens-node/recipe/emailpassword';
import EmailVerificationNode from 'supertokens-node/recipe/emailverification';
import SessionNode from 'supertokens-node/recipe/session';
import UserRolesNode from 'supertokens-node/recipe/userroles';
import type { TypeInput } from 'supertokens-node/types';
Expand Down Expand Up @@ -35,6 +36,9 @@ export const backendConfig = (): TypeInput => {
},
},
}),
EmailVerificationNode.init({
mode: process.env.NEXT_PUBLIC_WB_ENV === 'test' ? 'OPTIONAL' : 'REQUIRED',
}),
SessionNode.init(),
UserRolesNode.init(),
],
Expand Down
8 changes: 1 addition & 7 deletions src/infrastructures/supertokens/frontendConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,7 @@ export function setRouter(router: ReturnType<typeof useRouter>, pathName: string
export const frontendConfig = (): SuperTokensConfig => {
return {
appInfo,
recipeList: [
EmailPasswordReact.init(),
...(process.env.NEXT_PUBLIC_WB_VERSION === 'staging' || process.env.NEXT_PUBLIC_WB_VERSION === 'production'
? [EmailVerificationReact.init({ mode: 'REQUIRED' })]
: []),
SessionReact.init(),
],
recipeList: [EmailPasswordReact.init(), EmailVerificationReact.init({ mode: 'REQUIRED' }), SessionReact.init()],
windowHandler: (original) => ({
...original,
location: {
Expand Down

0 comments on commit cce35a1

Please sign in to comment.