diff --git a/layouts/AuthRedirect.tsx b/layouts/AuthRedirect.tsx index 916dc03..4fb32e5 100644 --- a/layouts/AuthRedirect.tsx +++ b/layouts/AuthRedirect.tsx @@ -20,14 +20,22 @@ export default function AuthRedirect({ children }: Props) { if (!router.pathname.startsWith("/public")) { if ( status === "authenticated" && - (router.pathname === "/login" || router.pathname === "/register") + (router.pathname === "/login" || + router.pathname === "/register" || + router.pathname === "/confirmation" || + router.pathname === "/forgot") ) { router.push("/").then(() => { setRedirect(false); }); } else if ( status === "unauthenticated" && - !(router.pathname === "/login" || router.pathname === "/register") + !( + router.pathname === "/login" || + router.pathname === "/register" || + router.pathname === "/confirmation" || + router.pathname === "/forgot" + ) ) { router.push("/login").then(() => { setRedirect(false); diff --git a/lib/api/sendVerificationRequest.ts b/lib/api/sendVerificationRequest.ts index 4cb85a2..b51db86 100644 --- a/lib/api/sendVerificationRequest.ts +++ b/lib/api/sendVerificationRequest.ts @@ -5,8 +5,6 @@ import { createTransport } from "nodemailer"; export default async function sendVerificationRequest( params: SendVerificationRequestParams ) { - console.log(params); - const { identifier, url, provider, theme } = params; const { host } = new URL(url); const transport = createTransport(provider.server); diff --git a/pages/api/auth/[...nextauth].ts b/pages/api/auth/[...nextauth].ts index 3f2d8ef..fc66184 100644 --- a/pages/api/auth/[...nextauth].ts +++ b/pages/api/auth/[...nextauth].ts @@ -10,6 +10,8 @@ import { Adapter } from "next-auth/adapters"; import sendVerificationRequest from "@/lib/api/sendVerificationRequest"; import { Provider } from "next-auth/providers"; +let email; + const providers: Provider[] = [ CredentialsProvider({ type: "credentials", @@ -63,6 +65,7 @@ if (process.env.EMAIL_SERVER && process.env.EMAIL_FROM) from: process.env.EMAIL_FROM, maxAge: 600, sendVerificationRequest(params) { + email = params.identifier; sendVerificationRequest(params); }, }) @@ -76,6 +79,7 @@ export const authOptions: AuthOptions = { providers, pages: { signIn: "/login", + verifyRequest: "/confirmation", }, callbacks: { session: async ({ session, token }: { session: Session; token: JWT }) => { diff --git a/components/Modal/EmailConfirmaion.tsx b/pages/confirmation.tsx similarity index 69% rename from components/Modal/EmailConfirmaion.tsx rename to pages/confirmation.tsx index 966287b..1c9a657 100644 --- a/components/Modal/EmailConfirmaion.tsx +++ b/pages/confirmation.tsx @@ -1,23 +1,24 @@ import { signIn } from "next-auth/react"; import React from "react"; -export default function EmailConfirmaion({ email }: { email: string }) { +export default function EmailConfirmaion() { return (
Please check your email
A sign in link has been sent to your email address.
-Linkwarden
diff --git a/pages/register.tsx b/pages/register.tsx index 8e22b76..c17db4a 100644 --- a/pages/register.tsx +++ b/pages/register.tsx @@ -3,7 +3,6 @@ import { useState } from "react"; import { toast } from "react-hot-toast"; import SubmitButton from "@/components/SubmitButton"; import { signIn } from "next-auth/react"; -import EmailConfirmaion from "@/components/Modal/EmailConfirmaion"; const EmailProvider = process.env.NEXT_PUBLIC_EMAIL_PROVIDER; @@ -17,7 +16,6 @@ type FormData = { export default function Register() { const [submitLoader, setSubmitLoader] = useState(false); - const [showConfirmation, setShowConfirmation] = useState(false); const [form, setForm] = useStateLinkwarden