Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added public/login/bg.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 56 additions & 0 deletions src/app/Login/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"use client";
import { useEffect, useState, Suspense } from "react";
import { useSession, signIn, signOut } from "next-auth/react";
import { useRouter, useSearchParams } from "next/navigation";

function Login(): React.JSX.Element {
const { data: session } = useSession();
const [alreadyLogin, setAlreadyLogin] = useState(false);
const router = useRouter();
const searchParams = useSearchParams();
const search = searchParams.get("next");

useEffect(() => {
if (session != null) {
setAlreadyLogin(true);
}
}, [session, router]);

return (
<div className="relative flex h-full min-h-screen w-full flex-col items-center justify-center gap-4 bg-[url('/login/bg.webp')] md:mx-auto md:max-w-[25rem]">
{alreadyLogin ? (
<div className="flex flex-col gap-4">
<button
className="rounded-[20px] bg-[#ECF0F6] p-4 text-2xl font-bold text-black transition-transform duration-300 hover:scale-105"
onClick={() => signOut()}
>
Google logout
</button>
<button
className="rounded-[20px] bg-[#ECF0F6] p-4 text-2xl font-bold text-black transition-transform duration-300 hover:scale-105"
onClick={() => {
router.push(search ? search : "/");
}}
>
Back to page
</button>
</div>
) : (
<button
className="rounded-[20px] bg-[#ECF0F6] p-4 text-2xl font-bold text-black transition-transform duration-300 hover:scale-105"
onClick={() => signIn("google")}
>
Google login
</button>
)}
</div>
);
}

export default function Page(): React.JSX.Element {
return (
<Suspense fallback={<p>loading...</p>}>
<Login />
</Suspense>
);
}
4 changes: 2 additions & 2 deletions src/components/authProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export default function AuthProvider({ children }: React.PropsWithChildren) {
const pathname = usePathname();

useEffect(() => {
if (session === null && pathname !== "/") {
router.push("/");
if (session === null && pathname !== "/Login") {
router.push(`/Login?next=${pathname}`);
}
}, [session, router, pathname]);

Expand Down
1 change: 1 addition & 0 deletions src/styles/globals.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import url("https://fonts.googleapis.com/css2?family=Anonymous+Pro:ital,wght@0,400;0,700;1,400;1,700&display=swap");
@tailwind base;
@tailwind components;
@tailwind utilities;
2 changes: 1 addition & 1 deletion tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
theme: {
extend: {
fontFamily: {
sans: ["var(--font-geist-sans)", ...fontFamily.sans],
sans: ["Anonymous Pro", ...fontFamily.sans],
},
},
},
Expand Down
Loading