diff --git a/src/components/AfterLogin/index.tsx b/src/components/AfterLogin/index.tsx
index fddcb08..7f232c1 100644
--- a/src/components/AfterLogin/index.tsx
+++ b/src/components/AfterLogin/index.tsx
@@ -1,6 +1,7 @@
'use client'
import { Link, useConfig } from '@payloadcms/ui'
+import { useSearchParams } from 'next/navigation.js'
import React from 'react'
import './index.scss'
@@ -8,6 +9,7 @@ import './index.scss'
const baseClass = 'after-login-otp'
export const AfterLoginOTP: React.FC = () => {
+ const redirect = useSearchParams().get('redirect')
const {
config: {
routes: { admin },
@@ -16,7 +18,9 @@ export const AfterLoginOTP: React.FC = () => {
return (
- Request a one-time password
+
+ Request a one-time password
+
)
}
diff --git a/src/components/LoginOTP/index.tsx b/src/components/LoginOTP/index.tsx
index 469d866..0a00a77 100644
--- a/src/components/LoginOTP/index.tsx
+++ b/src/components/LoginOTP/index.tsx
@@ -12,7 +12,7 @@ import {
useConfig,
useTranslation,
} from '@payloadcms/ui'
-import { useRouter } from 'next/navigation.js'
+import { useRouter, useSearchParams } from 'next/navigation.js'
import React from 'react'
import { getLoginOptions } from '../../utilities/getLoginOptions.js'
@@ -21,6 +21,7 @@ import { localStorageKey } from '../shared.js'
const baseClass = 'login-otp'
export const LoginOTP: React.FC = () => {
+ const redirect = useSearchParams().get('redirect')
const { config, getEntityConfig } = useConfig()
const { t } = useTranslation()
const router = useRouter()
@@ -57,9 +58,9 @@ export const LoginOTP: React.FC = () => {
})
const handleRedirect = React.useCallback(() => {
- router.push(admin)
+ router.push(redirect ?? admin)
window.localStorage.removeItem(localStorageKey)
- }, [router, admin])
+ }, [router, admin, redirect])
return (
diff --git a/src/components/RequestOTP/index.tsx b/src/components/RequestOTP/index.tsx
index 32bd1fc..bcedde6 100644
--- a/src/components/RequestOTP/index.tsx
+++ b/src/components/RequestOTP/index.tsx
@@ -13,7 +13,7 @@ import {
useConfig,
useTranslation,
} from '@payloadcms/ui'
-import { useRouter } from 'next/navigation.js'
+import { useRouter, useSearchParams } from 'next/navigation.js'
import { email, username } from 'payload/shared'
import React from 'react'
@@ -23,6 +23,7 @@ import { localStorageKey } from '../shared.js'
const baseClass = 'request-otp'
export const RequestOTP: React.FC = () => {
+ const redirect = useSearchParams().get('redirect')
const { config, getEntityConfig } = useConfig()
const { t } = useTranslation()
const router = useRouter()
@@ -50,10 +51,10 @@ export const RequestOTP: React.FC = () => {
const onSuccess = React.useCallback(
(args: unknown) => {
const { value } = args as { value: string }
- router.push(`${admin}/otp/login`)
+ router.push(`${admin}/otp/login${redirect ? '?redirect=' + redirect : ''}`)
window.localStorage.setItem(localStorageKey, value)
},
- [router, admin],
+ [router, admin, redirect],
)
return (