mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 00:03:33 +10:00
login logout toast
This commit is contained in:
@ -7,6 +7,7 @@ import { getCsrfToken, signIn } from "next-auth/react";
|
|||||||
import { ErrorCode } from "@documenso/lib/auth";
|
import { ErrorCode } from "@documenso/lib/auth";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
|
import { toast, Toaster } from "react-hot-toast";
|
||||||
|
|
||||||
interface LoginValues {
|
interface LoginValues {
|
||||||
email: string;
|
email: string;
|
||||||
@ -38,11 +39,25 @@ export default function Login() {
|
|||||||
callbackUrl,
|
callbackUrl,
|
||||||
redirect: false,
|
redirect: false,
|
||||||
});
|
});
|
||||||
if (!res) setErrorMessage("error");
|
if (!res) {
|
||||||
|
setErrorMessage("error");
|
||||||
|
toast.error("Something went wrong.");
|
||||||
|
}
|
||||||
// we're logged in! let's do a hard refresh to the desired url
|
// we're logged in! let's do a hard refresh to the desired url
|
||||||
else if (!res.error) router.push(callbackUrl);
|
else if (!res.error) {
|
||||||
|
router.push(callbackUrl).then(() => {
|
||||||
|
toast.success("Login successful");
|
||||||
|
});
|
||||||
|
// toast.error("error");
|
||||||
|
}
|
||||||
// fallback if error not found
|
// fallback if error not found
|
||||||
else setErrorMessage("something_went_wrong");
|
else {
|
||||||
|
if (res.status == 401) {
|
||||||
|
toast.error("Invalid email or password.");
|
||||||
|
} else {
|
||||||
|
toast.error("Could not login.");
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -141,6 +156,7 @@ export default function Login() {
|
|||||||
</FormProvider>
|
</FormProvider>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<Toaster position="top-center" />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import Link from "next/link";
|
|||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { signOut, useSession } from "next-auth/react";
|
import { signOut, useSession } from "next-auth/react";
|
||||||
import avatarFromInitials from "avatar-from-initials";
|
import avatarFromInitials from "avatar-from-initials";
|
||||||
|
import { toast, Toaster } from "react-hot-toast";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Bars3Icon,
|
Bars3Icon,
|
||||||
@ -48,9 +49,11 @@ const userNavigation = [
|
|||||||
{
|
{
|
||||||
name: "Sign out",
|
name: "Sign out",
|
||||||
href: "",
|
href: "",
|
||||||
click: (e: any) => {
|
click: async (e: any) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
signOut({ callbackUrl: "/login" });
|
const res: any = await signOut({ callbackUrl: "/login" }).finally(() => {
|
||||||
|
if (!res?.error) toast.success("Logout successful");
|
||||||
|
});
|
||||||
},
|
},
|
||||||
icon: ArrowRightOnRectangleIcon,
|
icon: ArrowRightOnRectangleIcon,
|
||||||
},
|
},
|
||||||
@ -226,6 +229,7 @@ export default function TopNavigation() {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</Disclosure>
|
</Disclosure>
|
||||||
|
<Toaster position="top-center"></Toaster>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,6 +10,7 @@ const nextConfig = {
|
|||||||
const withTM = require("next-transpile-modules")([
|
const withTM = require("next-transpile-modules")([
|
||||||
"@documenso/prisma",
|
"@documenso/prisma",
|
||||||
"@documenso/lib",
|
"@documenso/lib",
|
||||||
|
"@documenso/ui",
|
||||||
]);
|
]);
|
||||||
const plugins = [];
|
const plugins = [];
|
||||||
plugins.push(withTM);
|
plugins.push(withTM);
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@documenso/prisma": "*",
|
"@documenso/prisma": "*",
|
||||||
|
"@documenso/ui": "*",
|
||||||
"@headlessui/react": "^1.7.4",
|
"@headlessui/react": "^1.7.4",
|
||||||
"@heroicons/react": "^2.0.13",
|
"@heroicons/react": "^2.0.13",
|
||||||
"@tailwindcss/forms": "^0.5.3",
|
"@tailwindcss/forms": "^0.5.3",
|
||||||
|
|||||||
3
packages/lib/classNames.ts
Normal file
3
packages/lib/classNames.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export default function classNames(...classes: unknown[]) {
|
||||||
|
return classes.filter(Boolean).join(" ");
|
||||||
|
}
|
||||||
@ -1 +1,2 @@
|
|||||||
export { coloredConsole } from "./coloredConsole";
|
export { coloredConsole } from "./coloredConsole";
|
||||||
|
export { default as classNames } from "./classNames";
|
||||||
|
|||||||
1
packages/ui/components/index.ts
Normal file
1
packages/ui/components/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export { }
|
||||||
Reference in New Issue
Block a user