Skip to content

Commit

Permalink
Merge pull request #362 from boostcampwm-2024/Feat/360
Browse files Browse the repository at this point in the history
[Feat]: 게스트 로그인 생성
  • Loading branch information
zero0205 authored Dec 4, 2024
2 parents 65e9c49 + f46844a commit 8e77481
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
10 changes: 9 additions & 1 deletion apps/api/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AuthService } from './auth.service';
import { Controller, Get, Res, UseGuards } from '@nestjs/common';
import { Controller, Get, Post, Res, UseGuards } from '@nestjs/common';
import { GithubAuthGuard } from './guard/github-auth.guard';
import { GoogleAuthGuard } from './guard/google-auth.guard';
import { ApiTags } from '@nestjs/swagger';
Expand Down Expand Up @@ -45,4 +45,12 @@ export class AuthController {

res.redirect(`${CALLBACK_URI}/auth?accessToken=${accessToken}&isNecessaryInfo=${isNecessaryInfo}`);
}

@Post('/signin/guest')
@ApiTags(SwaggerTag.HEADER)
@ApiSuccessResponse(SuccessStatus.OK(SigninResponseDto), SigninResponseDto)
async signinGuest() {
const accessToken = await this.authService.createGuest();
return { accessToken };
}
}
13 changes: 13 additions & 0 deletions apps/api/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { SigninDto } from './dto/signin.dto';
import { CustomException } from 'src/common/responses/exceptions/custom.exception';
import { ErrorStatus } from 'src/common/responses/exceptions/errorStatus';
import { Member } from 'src/member/member.entity';
import { FieldEnum } from '../member/enum/field.enum';

@Injectable()
export class AuthService {
GUEST_ID = 1;
constructor(private readonly memberService: MemberService, private readonly jwtService: JwtService) {}

async validateOrCreateMember(signinDto: SigninDto) {
Expand Down Expand Up @@ -37,4 +39,15 @@ export class AuthService {

return member;
}

async createGuest() {
const member = new Member();
member.camperId = `guest${this.GUEST_ID}`;
member.name = `guest${this.GUEST_ID}`;
member.field = FieldEnum.WEB;
const newMember = await this.memberService.createMember(member);
const payload = { id: newMember.id, camperId: newMember.camperId };
console.log(payload);
return this.jwtService.sign(payload);
}
}

0 comments on commit 8e77481

Please sign in to comment.