-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 로그인 미들웨어, 로그아웃
- Loading branch information
Showing
11 changed files
with
118 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,8 @@ jobs: | |
fetch-depth: 0 | ||
|
||
- name: Code Review GPT | ||
uses: mattzcarey/[email protected].5 | ||
uses: mattzcarey/[email protected].8 | ||
with: | ||
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | ||
MODEL: 'gpt-3.5-turbo' | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
MODEL: 'gpt-4o' | ||
GITHUB_TOKEN: ${{ github.token }} |
23 changes: 23 additions & 0 deletions
23
prisma/migrations/20240526080214_add_provider/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
Warnings: | ||
- Added the required column `provider` to the `AuthToken` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- RedefineTables | ||
PRAGMA foreign_keys=OFF; | ||
CREATE TABLE "new_AuthToken" ( | ||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
"token" TEXT NOT NULL, | ||
"user_id" INTEGER NOT NULL, | ||
"provider" TEXT NOT NULL, | ||
"created_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updated_at" DATETIME NOT NULL, | ||
CONSTRAINT "AuthToken_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE | ||
); | ||
INSERT INTO "new_AuthToken" ("created_at", "id", "token", "updated_at", "user_id") SELECT "created_at", "id", "token", "updated_at", "user_id" FROM "AuthToken"; | ||
DROP TABLE "AuthToken"; | ||
ALTER TABLE "new_AuthToken" RENAME TO "AuthToken"; | ||
CREATE UNIQUE INDEX "AuthToken_token_key" ON "AuthToken"("token"); | ||
PRAGMA foreign_key_check; | ||
PRAGMA foreign_keys=ON; |
20 changes: 20 additions & 0 deletions
20
prisma/migrations/20240526081731_remove_username_required/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
-- RedefineTables | ||
PRAGMA foreign_keys=OFF; | ||
CREATE TABLE "new_User" ( | ||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
"username" TEXT, | ||
"email" TEXT, | ||
"password" TEXT, | ||
"phone" TEXT, | ||
"avatar" TEXT, | ||
"created_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updated_at" DATETIME NOT NULL | ||
); | ||
INSERT INTO "new_User" ("avatar", "created_at", "email", "id", "password", "phone", "updated_at", "username") SELECT "avatar", "created_at", "email", "id", "password", "phone", "updated_at", "username" FROM "User"; | ||
DROP TABLE "User"; | ||
ALTER TABLE "new_User" RENAME TO "User"; | ||
CREATE UNIQUE INDEX "User_username_key" ON "User"("username"); | ||
CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); | ||
CREATE UNIQUE INDEX "User_phone_key" ON "User"("phone"); | ||
PRAGMA foreign_key_check; | ||
PRAGMA foreign_keys=ON; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,26 @@ | ||
"use client"; | ||
|
||
import { Button } from "@material-tailwind/react"; | ||
import React from "react"; | ||
import { signOut } from "next-auth/react"; | ||
|
||
export default function Home() { | ||
return <div>home</div>; | ||
return ( | ||
<div className="py-10 flex flex-col items-center h-svh justify-evenly"> | ||
<h1>HOME</h1> | ||
<Button | ||
onClick={() => | ||
signOut({ | ||
redirect: true, | ||
callbackUrl: "/sign-in", | ||
}) | ||
} | ||
size="lg" | ||
color="white" | ||
className="w-80 flex justify-center hover:opacity-80 transition mt-4" | ||
> | ||
로그아웃 | ||
</Button> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,28 @@ | ||
"use server"; | ||
|
||
import db from "@/db"; | ||
import getSession from "@/utils/session"; | ||
|
||
export async function createUser({ provider }: { provider: string }) { | ||
const cookie = await getSession(); | ||
|
||
export async function checkSignInToken(token: string) { | ||
const user = await db.user.findUnique({ | ||
const user = await db.authToken.findUnique({ | ||
where: { | ||
username: "test", | ||
// AuthToken: { | ||
// some: { | ||
// token, | ||
// }, | ||
// }, | ||
token: cookie.id, | ||
}, | ||
select: { | ||
id: true, | ||
}, | ||
}); | ||
/// 유저가 존재하면 리턴 | ||
if (user) return; | ||
|
||
/// 없으면 유저 생성 | ||
await db.authToken.create({ | ||
data: { | ||
token: cookie.id, | ||
provider, | ||
user: {}, | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { NextRequest } from "next/server"; | ||
import getSession from "./utils/session"; | ||
|
||
export async function middleware(request: NextRequest) { | ||
const cookie = await getSession(); | ||
|
||
if (request.nextUrl.pathname === "/" && cookie.id === undefined) { | ||
return Response.redirect(new URL("/sign-in", request.url)); | ||
} | ||
|
||
if (request.nextUrl.pathname === "/sign-in" && cookie.id !== undefined) { | ||
return Response.redirect(new URL("/", request.url)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
type LoginProvider = "kakao" | "google"; | ||
|
||
export type { LoginProvider }; |