Skip to content

Commit

Permalink
refactor: Oauth 유저 타입 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
Miensoap committed Nov 21, 2024
1 parent 0365e92 commit 8b4bd76
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
6 changes: 6 additions & 0 deletions backend/src/auth/auth.type.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
export type OAuthUserInfo = {
oauthId: string;
nickname: string;
profileImageUrl: string;
};

export type googleTokenResponse = {
access_token: string;
};
Expand Down
12 changes: 8 additions & 4 deletions backend/src/auth/oauthProvider/GoogleOAuthProvider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { OAuthProvider } from './OAuthProvider';
import { addBearerToken } from '../utils';
import { AuthenticationException } from '../exception/AuthenticationException';
import { isGoogleTokenResponse, isGoogleUserResponse } from '../auth.type';
import {
isGoogleTokenResponse,
isGoogleUserResponse,
OAuthUserInfo,
} from '../auth.type';
import { ConfigService } from '@nestjs/config';
import { OAuthProviders } from './OAuthProviders';

Expand Down Expand Up @@ -41,7 +45,7 @@ export class GoogleOAuthProvider extends OAuthProvider {
return data.access_token;
}

async getUserInfo(code: string): Promise<any> {
async getUserInfo(code: string): Promise<OAuthUserInfo> {
const token = await this.getToken(code);
const response = await fetch(
'https://www.googleapis.com/oauth2/v2/userinfo',
Expand All @@ -59,8 +63,8 @@ export class GoogleOAuthProvider extends OAuthProvider {
}
return {
oauthId: data.id,
name: data.name,
picture: data.picture,
nickname: data.name,
profileImageUrl: data.picture,
};
}
}
3 changes: 2 additions & 1 deletion backend/src/auth/oauthProvider/OAuthProvider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ConfigService } from '@nestjs/config';
import { OAuthProviders } from './OAuthProviders';
import { OAuthUserInfo } from '@src/auth/auth.type';

export abstract class OAuthProvider {
protected readonly clientId: string;
Expand All @@ -25,5 +26,5 @@ export abstract class OAuthProvider {

abstract getAuthUrl(): string;

abstract getUserInfo(token: string): Promise<any>;
abstract getUserInfo(token: string): Promise<OAuthUserInfo>;
}

0 comments on commit 8b4bd76

Please sign in to comment.