nishimura.clubnishimura.club

NextAuthでsignInとsignOut時に特定のURLにリダイレクトさせる

作成日
2021-09-07
更新日
2021-09-07

ドキュメント

実装

callbackUrl使う。

import { signIn, signOut } from 'next-auth/client'; signIn('google'{ callbackUrl: `http://localhost/foo` }); signOut({ callbackUrl: `http://localhost/foo` });

envを使う

.env.local
NEXT_PUBLIC_BASE_URL="http://localhost:3000"
import { signIn, signOut } from 'next-auth/client'; signIn('google', { callbackUrl: `${ process.env.NEXT_PUBLIC_BASE_URL || 'http://localhost:3000' }/foo`, }); signOut({ callbackUrl: `${ process.env.NEXT_PUBLIC_BASE_URL || 'http://localhost:3000' }/foo`, });

||はもっといい使い方あるかも。

env.local を修正したら、再起動しましょう。

Related

Tags

NextJS

Share

Table of Contents