Skip to content

Commit

Permalink
feat : api전달시 deviceType도 같이 보내도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
0xC0FFE2 committed Jan 21, 2025
1 parent 3195b65 commit 32ed80e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/services/AuthService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ export class AuthService {
static async execute(data: LoginRequest): Promise<void> {
let endpoint = "";

if (data.requestType === RequestType.DASHBOARD) {
if (data.requestType === RequestType.DASHBOARD &&data.authType === AuthType.APP) {
endpoint = `${BASE_URL}/auth/app-login`;
} else if (data.requestType === RequestType.DASHBOARD && data.authType === AuthType.PIN) {
endpoint = `${BASE_URL}/auth/login`;
} else if (data.requestType === RequestType.OAUTH &&data.authType === AuthType.APP) {
endpoint = `${BASE_URL}/oauth/app-login`;
} else {
endpoint = `${BASE_URL}/auth/oauth_login`;
endpoint = `${BASE_URL}/oauth/login`;
}

console.log(endpoint);
Expand All @@ -30,6 +34,7 @@ export class AuthService {
"Content-Type": "application/json",
},
body: JSON.stringify(requestBody),
mode: 'cors',
});

const result = await response.json();
Expand Down
20 changes: 19 additions & 1 deletion src/services/dto/request/LoginRequestViaApp.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
import { DeviceType } from "../../../types/DeviceType";
import { LoginRequest } from "./LoginRequest";

export function loginRequestViaApp(data: LoginRequest): any {
return {
email: data.email,
password: data.password
password: data.password,
deviceType: getDeviceType(),
};
}

function getDeviceType(): DeviceType {
const userAgent = navigator.userAgent;

if (/Android/i.test(userAgent)) {
return DeviceType.ANDROID;
} else if (/iPhone|iPad|iPod/i.test(userAgent)) {
return DeviceType.IOS;
} else if (/Windows NT/i.test(userAgent)) {
return DeviceType.WINDOWS;
} else if (/Macintosh/i.test(userAgent)) {
return DeviceType.MAC;
} else {
return DeviceType.WEB_UNKNOWN;
}
}
18 changes: 18 additions & 0 deletions src/services/dto/request/LoginRequestViaPin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DeviceType } from '../../../types/DeviceType';
import { LoginRequest } from './LoginRequest';

export function loginRequestViaPin(data: LoginRequest): any {
Expand All @@ -6,5 +7,22 @@ export function loginRequestViaPin(data: LoginRequest): any {
password: data.password,
recaptchaToken: data.recaptchaToken,
pin: data.password,
deviceType: getDeviceType(),
};
}

function getDeviceType(): DeviceType {
const userAgent = navigator.userAgent;

if (/Android/i.test(userAgent)) {
return DeviceType.ANDROID;
} else if (/iPhone|iPad|iPod/i.test(userAgent)) {
return DeviceType.IOS;
} else if (/Windows NT/i.test(userAgent)) {
return DeviceType.WINDOWS;
} else if (/Macintosh/i.test(userAgent)) {
return DeviceType.MAC;
} else {
return DeviceType.WEB_UNKNOWN;
}
}
7 changes: 7 additions & 0 deletions src/types/DeviceType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export enum DeviceType {
WEB_UNKNOWN = "WEB_UNKNOWN",
ANDROID = "ANDROID",
IOS = "IOS",
WINDOWS = "WINDOWS",
MAC = "MAC",
}

0 comments on commit 32ed80e

Please sign in to comment.