fix(auth): replace hardcoded platform name with dynamic platform detection
This commit is contained in:
@@ -16,7 +16,7 @@ import {
|
||||
SendCodeRequest,
|
||||
} from "@/data/dto/auth";
|
||||
import { User } from "@/data/dto/user";
|
||||
import { AppEnvUtil, Result, Logger } from "@/utils";
|
||||
import { AppEnvUtil, PlatformDetector, Result, Logger } from "@/utils";
|
||||
import type { IAuthRepository } from "@/data/repositories/interfaces";
|
||||
import { AuthStorage, type IAuthStorage } from "@/data/storage/auth";
|
||||
import { UserStorage, type IUserStorage } from "@/data/storage/user";
|
||||
@@ -24,8 +24,6 @@ import { createLazySingleton } from "./lazy_singleton";
|
||||
|
||||
const log = new Logger("DataRepositoriesAuthRepository");
|
||||
|
||||
/** 硬编码平台名,对齐 Dart `PlatformUtil.platformName.toLowerCase()`(Web 平台)。 */
|
||||
const WEB_PLATFORM = "web";
|
||||
const TEST_ACCOUNT_FLAG = "isTestAccount";
|
||||
|
||||
export class AuthRepository implements IAuthRepository {
|
||||
@@ -54,7 +52,7 @@ export class AuthRepository implements IAuthRepository {
|
||||
username: input.username,
|
||||
email: input.email,
|
||||
password: input.password,
|
||||
platform: WEB_PLATFORM,
|
||||
platform: getAuthPlatform(),
|
||||
guestId: input.guestId ?? "",
|
||||
}),
|
||||
),
|
||||
@@ -76,7 +74,7 @@ export class AuthRepository implements IAuthRepository {
|
||||
email: input.email ?? "",
|
||||
username: input.username ?? "",
|
||||
password: input.password,
|
||||
platform: WEB_PLATFORM,
|
||||
platform: getAuthPlatform(),
|
||||
guestId: input.guestId ?? "",
|
||||
}),
|
||||
),
|
||||
@@ -157,7 +155,7 @@ export class AuthRepository implements IAuthRepository {
|
||||
GoogleLoginRequest.from(
|
||||
withTestAccountFlag({
|
||||
idToken: input.idToken,
|
||||
platform: WEB_PLATFORM,
|
||||
platform: getAuthPlatform(),
|
||||
guestId: input.guestId ?? "",
|
||||
}),
|
||||
),
|
||||
@@ -175,7 +173,7 @@ export class AuthRepository implements IAuthRepository {
|
||||
FacebookLoginRequest.from(
|
||||
withTestAccountFlag({
|
||||
accessToken: input.accessToken,
|
||||
platform: WEB_PLATFORM,
|
||||
platform: getAuthPlatform(),
|
||||
guestId: input.guestId ?? "",
|
||||
}),
|
||||
),
|
||||
@@ -211,7 +209,7 @@ export class AuthRepository implements IAuthRepository {
|
||||
AppleLoginRequest.from(
|
||||
withTestAccountFlag({
|
||||
identityToken,
|
||||
platform: WEB_PLATFORM,
|
||||
platform: getAuthPlatform(),
|
||||
}),
|
||||
),
|
||||
),
|
||||
@@ -319,3 +317,7 @@ function withTestAccountFlag<T extends Record<string, unknown>>(
|
||||
[TEST_ACCOUNT_FLAG]: !AppEnvUtil.isProduction(),
|
||||
};
|
||||
}
|
||||
|
||||
function getAuthPlatform(): string {
|
||||
return PlatformDetector.getPlatform();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user