From 01317fba8f2012dffc68aab43eaa6250241f9be5 Mon Sep 17 00:00:00 2001 From: LeeJongBeom <52884648+devleejb@users.noreply.github.com> Date: Fri, 19 Jan 2024 13:28:51 +0900 Subject: [PATCH] (FE) Add User registration / Login (#69) * Change router path * Add favicon * Add main header * Add redirection to auth callback router * Add Base API Url to env * Add SocialButtons deps * Add login Page * Add get token logic from redirect url * Add redux persist to store accessToken in localstorage * Add auth reducer * Add redux-persist * Add ignoredActions - redux-persist --- backend/src/auth/auth.controller.ts | 12 +++- frontend/.env.development | 5 +- frontend/index.html | 8 ++- frontend/package-lock.json | 18 ++++++ frontend/package.json | 2 + frontend/public/favicon-16x16.png | Bin 0 -> 523 bytes frontend/public/favicon-32x32.png | Bin 0 -> 915 bytes frontend/public/favicon-512x512.png | Bin 0 -> 4188 bytes frontend/public/favicon.ico | Bin 0 -> 16958 bytes frontend/src/App.tsx | 21 +++++- .../src/components/headers/MainHeader.tsx | 23 +++++++ .../src/components/icons/CodePairIcon.tsx | 33 ++++++++++ .../src/components/layouts/MainLayout.tsx | 12 ++++ frontend/src/main.tsx | 8 ++- frontend/src/pages/Index.tsx | 60 ++++++++++++++++++ frontend/src/pages/auth/callback/Index.tsx | 26 ++++++++ frontend/src/store/authSlice.ts | 27 ++++++++ frontend/src/store/store.ts | 32 ++++++++-- 18 files changed, 271 insertions(+), 16 deletions(-) create mode 100644 frontend/public/favicon-16x16.png create mode 100644 frontend/public/favicon-32x32.png create mode 100644 frontend/public/favicon-512x512.png create mode 100644 frontend/public/favicon.ico create mode 100644 frontend/src/components/headers/MainHeader.tsx create mode 100644 frontend/src/components/icons/CodePairIcon.tsx create mode 100644 frontend/src/components/layouts/MainLayout.tsx create mode 100644 frontend/src/pages/Index.tsx create mode 100644 frontend/src/pages/auth/callback/Index.tsx create mode 100644 frontend/src/store/authSlice.ts diff --git a/backend/src/auth/auth.controller.ts b/backend/src/auth/auth.controller.ts index 17f1dc7e..a6eb4657 100644 --- a/backend/src/auth/auth.controller.ts +++ b/backend/src/auth/auth.controller.ts @@ -1,4 +1,4 @@ -import { Controller, Get, Req, UseGuards } from "@nestjs/common"; +import { Controller, Get, HttpRedirectResponse, Redirect, Req, UseGuards } from "@nestjs/common"; import { AuthGuard } from "@nestjs/passport"; import { LoginRequest } from "./types/login-request.type"; import { JwtService } from "@nestjs/jwt"; @@ -6,11 +6,13 @@ import { LoginResponse } from "./types/login-response.type"; import { UsersService } from "src/users/users.service"; import { Public } from "src/utils/decorators/auth.decorator"; import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger"; +import { ConfigService } from "@nestjs/config"; @ApiTags("Auth") @Controller("auth") export class AuthController { constructor( + private configService: ConfigService, private jwtService: JwtService, private usersService: UsersService ) {} @@ -18,13 +20,14 @@ export class AuthController { @Public() @Get("login/github") @Get("callback/github") + @Redirect() @UseGuards(AuthGuard("github")) @ApiOperation({ summary: "SignUp/LogIn with GitHub", description: "SignUp/Login with GitHub social login", }) @ApiResponse({ type: LoginResponse }) - async login(@Req() req: LoginRequest): Promise { + async login(@Req() req: LoginRequest): Promise { const user = await this.usersService.findOrCreate( req.user.socialProvider, req.user.socialUid, @@ -33,6 +36,9 @@ export class AuthController { const accessToken = this.jwtService.sign({ sub: user.id, nickname: user.nickname }); - return { accessToken }; + return { + url: `${this.configService.get("FRONTEND_BASE_URL")}/auth/callback?token=${accessToken}`, + statusCode: 302, + }; } } diff --git a/frontend/.env.development b/frontend/.env.development index 7f71c03e..be08dbc1 100644 --- a/frontend/.env.development +++ b/frontend/.env.development @@ -1,2 +1,3 @@ -VITE_YORKIE_API_ADDR='https://api.yorkie.dev' -VITE_YORKIE_API_KEY='cmftp10ksk14av0kc7gg' +VITE_API_ADDR="http://localhost:3000" +VITE_YORKIE_API_ADDR="https://api.yorkie.dev" +VITE_YORKIE_API_KEY="cmftp10ksk14av0kc7gg" diff --git a/frontend/index.html b/frontend/index.html index 6004d283..aa9e1caf 100755 --- a/frontend/index.html +++ b/frontend/index.html @@ -2,9 +2,13 @@ - + + + + - Vite + React + TS + + CodePair