Skip to content

Commit

Permalink
Merge pull request #41 from rlarlduf20/#40-auth
Browse files Browse the repository at this point in the history
#40 auth
  • Loading branch information
rlarlduf20 authored Jan 22, 2024
2 parents cfe5063 + c3f2b68 commit b1a9ad2
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 2 deletions.
Binary file added public/images/sign/kakao_login_btn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/sign/naver_login_btn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/sign/signIn-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/app/(main)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ const RootLayout = async ({
<body>
<AuthSessionProvider>
<Header />
<main className="w-inner mx-auto">
<main className="w-inner h-[calc(100vh-80px)] mx-auto">
{children}
{addAlbumModal}
{addMateModal}
</main>
<Footer />
{/* <Footer /> */}
</AuthSessionProvider>
</body>
</html>
Expand Down
12 changes: 12 additions & 0 deletions src/app/(main)/signIn/error/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import SignButton from "@/components/SignButton";

const SignError = () => {
return (
<section>
<p>오류가 발생했습니다. 다시 로그인 해주세요.</p>
<SignButton />
</section>
);
};

export default SignError;
7 changes: 7 additions & 0 deletions src/app/(main)/signIn/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import SignInSection from "@/templates/SignInSection";

const SignIn = () => {
return <SignInSection />;
};

export default SignIn;
4 changes: 4 additions & 0 deletions src/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export const authOptions = {
clientSecret: process.env.NAVER_CLIENT_SECRET ?? "",
}),
],
pages: {
signIn: "/signIn",
error: "/signIn/error",
},
callbacks: {
async signIn({ user, account }: any) {
let userData = {
Expand Down
38 changes: 38 additions & 0 deletions src/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { getToken } from "next-auth/jwt";
import { NextRequest, NextResponse } from "next/server";

const withAuthList = ["/browse", "/album", "/addAlbum", "/addMate"];
const withOutAuthList = ["/signIn"];

const withAuth = async (req: NextRequest, token: boolean) => {
const url = req.nextUrl.clone();

if (!token) {
url.pathname = "/signIn";

return NextResponse.redirect(url);
}
};

const withOutAuth = async (req: NextRequest, token: boolean) => {
const url = req.nextUrl.clone();

if (token) {
return NextResponse.redirect(url.origin);
}
};

export default async function middleware(req: NextRequest) {
const token = await getToken({ req });
const pathname = req.nextUrl.pathname;

const isWithAuth = withAuthList.includes(pathname);
const isWithOutAuth = withOutAuthList.includes(pathname);

if (isWithAuth) return withAuth(req, !!token);
if (isWithOutAuth) return withOutAuth(req, !!token);
}

export const config = {
matcher: [...withAuthList, ...withOutAuthList],
};
30 changes: 30 additions & 0 deletions src/templates/SignInSection/SignInBox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use client";

import Image from "next/image";
import KakaoLoginBtn from "../../../public/images/sign/kakao_login_btn.png";
import NaverLoginBtn from "../../../public/images/sign/naver_login_btn.png";
import { signIn } from "next-auth/react";

const SignInBox = () => {
return (
<div>
<Image
src={KakaoLoginBtn}
alt="카카오 로그인"
className="mb-[15px] cursor-pointer"
width={330}
onClick={() => signIn("kakao")}
/>

<Image
src={NaverLoginBtn}
alt="네이버 로그인"
className="cursor-pointer"
width={330}
onClick={() => signIn("naver")}
/>
</div>
);
};

export default SignInBox;
17 changes: 17 additions & 0 deletions src/templates/SignInSection/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Image from "next/image";
import SignInLogo from "../../../public/images/sign/signIn-logo.png";
import SignInBox from "./SignInBox";

const SignInSection = () => {
return (
<section className="w-full h-full flex flex-col items-center justify-center gap-[55px] mt-[-80px]">
<div className="text-center">
<Image src={SignInLogo} alt="로고" />
<p className="text-[24px]">로그인</p>
</div>
<SignInBox />
</section>
);
};

export default SignInSection;

0 comments on commit b1a9ad2

Please sign in to comment.