Skip to content

Commit

Permalink
Feat: 토익 문제 업로드 로직 추가
Browse files Browse the repository at this point in the history
- 토익 문제 모듈 추가
- 토익, 문제 업로드 서비스 로직 추가
- 어드민 유저만 업로드 가능하도록 권한 설정
Related to #18
  • Loading branch information
Zamoca42 committed Feb 7, 2024
1 parent ce2130e commit 484d1b0
Show file tree
Hide file tree
Showing 14 changed files with 415 additions and 54 deletions.
2 changes: 2 additions & 0 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { JwtAuthGuard } from './auth/guard/jwt-auth.guard';
import { UploadModule } from './upload/upload.module';
import { RolesGuard } from './auth/guard/roles.guard';
import { JwtModule } from '@nestjs/jwt';
import { ToeicModule } from './toeic/toeic.module';

@Module({
imports: [
Expand All @@ -17,6 +18,7 @@ import { JwtModule } from '@nestjs/jwt';
SupabaseModule,
AuthModule,
UploadModule,
ToeicModule,
],
providers: [
{
Expand Down
2 changes: 1 addition & 1 deletion backend/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class AuthController {

@Get('user')
@ApiSwagger({ name: '유저 정보 조회(임시)', model: AuthResponse })
@Roles([Role.AUTH])
@Roles([Role.AUTH, Role.ADMIN])
async getUser() {
const response = await this.authService.getCurrentUser();
return ResponseEntity.OK_WITH('Successfully find user', response);
Expand Down
1 change: 1 addition & 0 deletions backend/src/auth/auth.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export interface Payload {
phone: string;
role: string;
session_id: string;
app_metadata: { provider: string; proviers: string[] };
}
8 changes: 4 additions & 4 deletions backend/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ export class AuthService {
async signInWith(credentials: CredentialProps): Promise<AuthResponse> {
const { data, error } =
await this.supabaseService.client.auth.signInWithPassword(credentials);
this.supabaseService.exception(error);
this.supabaseService.authFail(error);
return new AuthResponse(data.session, credentials.email);
}

async signUpWith(credentials: CredentialProps): Promise<void> {
const { data, error } =
await this.supabaseService.client.auth.signUp(credentials);
this.supabaseService.exception(error);
this.supabaseService.authFail(error);
if (this.checkUserRole(data.user) === '') {
throw new UnauthorizedException('User already registered');
}
Expand All @@ -32,7 +32,7 @@ export class AuthService {
refresh_token: refreshToken,
access_token: accessToken,
});
this.supabaseService.exception(error);
this.supabaseService.authFail(error);
return new AuthResponse(data.session);
}

Expand All @@ -46,6 +46,6 @@ export class AuthService {

async signOut(): Promise<void> {
const { error } = await this.supabaseService.client.auth.signOut();
this.supabaseService.exception(error);
this.supabaseService.authFail(error);
}
}
2 changes: 1 addition & 1 deletion backend/src/auth/constant/roles.enum.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export enum Role {
ADMIN = 'servcie_role',
ADMIN = 'supabase_admin',
AUTH = 'authenticated',
}
1 change: 1 addition & 0 deletions backend/src/auth/guard/roles.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class RolesGuard implements CanActivate {
const request = context.switchToHttp().getRequest();
const token = this.getToken(request);
const payload = this.decodeToken(token);
console.log(payload);

return this.matchRoles(roles, payload.role);
}
Expand Down
Loading

0 comments on commit 484d1b0

Please sign in to comment.