From cce35a125544980c86ad60a5f99750a6771f7aec Mon Sep 17 00:00:00 2001 From: "Sakamoto, Kazunori" Date: Wed, 18 Sep 2024 23:59:52 +0900 Subject: [PATCH] fix: tweak supertokens settings --- src/app/auth/[[...path]]/page.tsx | 5 +++-- src/infrastructures/supertokens/backendConfig.ts | 4 ++++ src/infrastructures/supertokens/frontendConfig.ts | 8 +------- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/app/auth/[[...path]]/page.tsx b/src/app/auth/[[...path]]/page.tsx index cf2ccfce..3c50bff5 100644 --- a/src/app/auth/[[...path]]/page.tsx +++ b/src/app/auth/[[...path]]/page.tsx @@ -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'; @@ -16,7 +17,7 @@ const AuthPage: NextPage = () => { // サインイン/アップに伴う画面表示の変更を反映するために、全ページのキャッシュを削除する。 void clearAllCaches(); - if (SuperTokens.canHandleRoute([EmailPasswordPreBuiltUI])) { + if (SuperTokens.canHandleRoute([EmailPasswordPreBuiltUI, EmailVerificationPreBuiltUI])) { setLoaded(true); } else { void redirectToAuth({ redirectBack: false }); @@ -24,7 +25,7 @@ const AuthPage: NextPage = () => { }, []); if (loaded) { - return SuperTokens.getRoutingComponent([EmailPasswordPreBuiltUI]); + return SuperTokens.getRoutingComponent([EmailPasswordPreBuiltUI, EmailVerificationPreBuiltUI]); } }; diff --git a/src/infrastructures/supertokens/backendConfig.ts b/src/infrastructures/supertokens/backendConfig.ts index c88bfcd0..52287650 100644 --- a/src/infrastructures/supertokens/backendConfig.ts +++ b/src/infrastructures/supertokens/backendConfig.ts @@ -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'; @@ -35,6 +36,9 @@ export const backendConfig = (): TypeInput => { }, }, }), + EmailVerificationNode.init({ + mode: process.env.NEXT_PUBLIC_WB_ENV === 'test' ? 'OPTIONAL' : 'REQUIRED', + }), SessionNode.init(), UserRolesNode.init(), ], diff --git a/src/infrastructures/supertokens/frontendConfig.ts b/src/infrastructures/supertokens/frontendConfig.ts index ef2a440e..42bf3ae7 100644 --- a/src/infrastructures/supertokens/frontendConfig.ts +++ b/src/infrastructures/supertokens/frontendConfig.ts @@ -17,13 +17,7 @@ export function setRouter(router: ReturnType, 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: {