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