Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

fixes and improvements

Daniel7be3b37b213b
diff --git a/layouts/AuthRedirect.tsx b/layouts/AuthRedirect.tsx
index 916dc031..4fb32e51 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 4cb85a25..b51db86d 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 3f2d8ef0..fc66184b 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 966287b8..1c9a657d 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 (
<div className="overflow-y-auto py-2 fixed top-0 bottom-0 right-0 left-0 bg-gray-500 bg-opacity-10 backdrop-blur-sm flex items-center fade-in z-30">
- <div className="mx-auto p-3 rounded-xl border border-sky-100 shadow-lg bg-gray-100 text-sky-800">
+ <div className="mx-auto p-3 text-center rounded-xl border border-sky-100 shadow-lg bg-gray-100 text-sky-800">
<p className="text-center text-2xl mb-2">Please check your email</p>
<p>A sign in link has been sent to your email address.</p>
- <div
+ <p>You can safely close this page.</p>
+ {/* <div
onClick={() =>
signIn("email", {
- email,
+ email: email,
redirect: false,
})
}
className="mx-auto font-semibold mt-2 cursor-pointer w-fit"
>
Resend?
- </div>
+ </div> */}
</div>
</div>
);
diff --git a/pages/forgot.tsx b/pages/forgot.tsx
index 2ae20291..ee7cd469 100644
--- a/pages/forgot.tsx
+++ b/pages/forgot.tsx
@@ -1,4 +1,3 @@
-import EmailConfirmaion from "@/components/Modal/EmailConfirmaion";
import SubmitButton from "@/components/SubmitButton";
import { signIn } from "next-auth/react";
import Link from "next/link";
@@ -11,7 +10,6 @@ interface FormData {
export default function Forgot() {
const [submitLoader, setSubmitLoader] = useState(false);
- const [showConfirmation, setShowConfirmation] = useState(false);
const [form, setForm] = useState<FormData>({
email: "",
@@ -23,20 +21,16 @@ export default function Forgot() {
const load = toast.loading("Sending login link...");
- const res = await signIn("email", {
+ await signIn("email", {
email: form.email,
- callbackUrl: window.location.origin,
+ callbackUrl: "/",
});
- setShowConfirmation(true);
-
toast.dismiss(load);
setSubmitLoader(false);
- if (!res?.ok) {
- toast.error("Invalid login.");
- }
+ toast.success("Login link sent.");
} else {
toast.error("Please fill out all the fields.");
}
@@ -44,9 +38,6 @@ export default function Forgot() {
return (
<>
- {showConfirmation && form.email ? (
- <EmailConfirmaion email={form.email} />
- ) : undefined}
<p className="text-xl font-bold text-center text-sky-500 mt-10 mb-3">
Linkwarden
</p>
diff --git a/pages/register.tsx b/pages/register.tsx
index 8e22b763..c17db4a2 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] = useState<FormData>({
name: "",
@@ -50,7 +48,7 @@ export default function Register() {
const sendConfirmation = async () => {
await signIn("email", {
email: form.email,
- redirect: false,
+ callbackUrl: "/",
});
};
@@ -76,10 +74,7 @@ export default function Register() {
setSubmitLoader(false);
if (response.ok) {
- if (form.email) {
- await sendConfirmation();
- setShowConfirmation(true);
- }
+ if (form.email) await sendConfirmation();
toast.success(
EmailProvider
@@ -99,9 +94,6 @@ export default function Register() {
return (
<>
- {showConfirmation && form.email ? (
- <EmailConfirmaion email={form.email} />
- ) : undefined}
<p className="text-xl font-bold text-center my-10 mb-3 text-sky-500">
Linkwarden
</p>