mirror of
https://github.com/shadcn-ui/taxonomy
synced 2026-05-23 09:18:30 +00:00
Merge branch 'main' into feat/contentlayer
This commit is contained in:
commit
ae8213e489
2 changed files with 11 additions and 2 deletions
|
|
@ -1,6 +1,7 @@
|
|||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { useSearchParams } from "next/navigation"
|
||||
import { signIn } from "next-auth/react"
|
||||
import * as z from "zod"
|
||||
import { useForm } from "react-hook-form"
|
||||
|
|
@ -24,6 +25,7 @@ export function UserAuthForm({ className, ...props }: UserAuthFormProps) {
|
|||
resolver: zodResolver(userAuthSchema),
|
||||
})
|
||||
const [isLoading, setIsLoading] = React.useState<boolean>(false)
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
async function onSubmit(data: FormData) {
|
||||
setIsLoading(true)
|
||||
|
|
@ -31,7 +33,7 @@ export function UserAuthForm({ className, ...props }: UserAuthFormProps) {
|
|||
const signInResult = await signIn("email", {
|
||||
email: data.email.toLowerCase(),
|
||||
redirect: false,
|
||||
callbackUrl: `${window.location.origin}/dashboard`,
|
||||
callbackUrl: searchParams.get("from") || "/dashboard",
|
||||
})
|
||||
|
||||
setIsLoading(false)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,14 @@ export default withAuth(
|
|||
}
|
||||
|
||||
if (!isAuth) {
|
||||
return NextResponse.redirect(new URL("/login", req.url))
|
||||
let from = req.nextUrl.pathname;
|
||||
if (req.nextUrl.search) {
|
||||
from += req.nextUrl.search;
|
||||
}
|
||||
|
||||
return NextResponse.redirect(
|
||||
new URL(`/login?from=${encodeURIComponent(from)}`, req.url)
|
||||
);
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue