fix(auth): replace hardcoded platform name with dynamic platform detection
This commit is contained in:
@@ -16,7 +16,7 @@ import {
|
|||||||
SendCodeRequest,
|
SendCodeRequest,
|
||||||
} from "@/data/dto/auth";
|
} from "@/data/dto/auth";
|
||||||
import { User } from "@/data/dto/user";
|
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 type { IAuthRepository } from "@/data/repositories/interfaces";
|
||||||
import { AuthStorage, type IAuthStorage } from "@/data/storage/auth";
|
import { AuthStorage, type IAuthStorage } from "@/data/storage/auth";
|
||||||
import { UserStorage, type IUserStorage } from "@/data/storage/user";
|
import { UserStorage, type IUserStorage } from "@/data/storage/user";
|
||||||
@@ -24,8 +24,6 @@ import { createLazySingleton } from "./lazy_singleton";
|
|||||||
|
|
||||||
const log = new Logger("DataRepositoriesAuthRepository");
|
const log = new Logger("DataRepositoriesAuthRepository");
|
||||||
|
|
||||||
/** 硬编码平台名,对齐 Dart `PlatformUtil.platformName.toLowerCase()`(Web 平台)。 */
|
|
||||||
const WEB_PLATFORM = "web";
|
|
||||||
const TEST_ACCOUNT_FLAG = "isTestAccount";
|
const TEST_ACCOUNT_FLAG = "isTestAccount";
|
||||||
|
|
||||||
export class AuthRepository implements IAuthRepository {
|
export class AuthRepository implements IAuthRepository {
|
||||||
@@ -54,7 +52,7 @@ export class AuthRepository implements IAuthRepository {
|
|||||||
username: input.username,
|
username: input.username,
|
||||||
email: input.email,
|
email: input.email,
|
||||||
password: input.password,
|
password: input.password,
|
||||||
platform: WEB_PLATFORM,
|
platform: getAuthPlatform(),
|
||||||
guestId: input.guestId ?? "",
|
guestId: input.guestId ?? "",
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
@@ -76,7 +74,7 @@ export class AuthRepository implements IAuthRepository {
|
|||||||
email: input.email ?? "",
|
email: input.email ?? "",
|
||||||
username: input.username ?? "",
|
username: input.username ?? "",
|
||||||
password: input.password,
|
password: input.password,
|
||||||
platform: WEB_PLATFORM,
|
platform: getAuthPlatform(),
|
||||||
guestId: input.guestId ?? "",
|
guestId: input.guestId ?? "",
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
@@ -157,7 +155,7 @@ export class AuthRepository implements IAuthRepository {
|
|||||||
GoogleLoginRequest.from(
|
GoogleLoginRequest.from(
|
||||||
withTestAccountFlag({
|
withTestAccountFlag({
|
||||||
idToken: input.idToken,
|
idToken: input.idToken,
|
||||||
platform: WEB_PLATFORM,
|
platform: getAuthPlatform(),
|
||||||
guestId: input.guestId ?? "",
|
guestId: input.guestId ?? "",
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
@@ -175,7 +173,7 @@ export class AuthRepository implements IAuthRepository {
|
|||||||
FacebookLoginRequest.from(
|
FacebookLoginRequest.from(
|
||||||
withTestAccountFlag({
|
withTestAccountFlag({
|
||||||
accessToken: input.accessToken,
|
accessToken: input.accessToken,
|
||||||
platform: WEB_PLATFORM,
|
platform: getAuthPlatform(),
|
||||||
guestId: input.guestId ?? "",
|
guestId: input.guestId ?? "",
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
@@ -211,7 +209,7 @@ export class AuthRepository implements IAuthRepository {
|
|||||||
AppleLoginRequest.from(
|
AppleLoginRequest.from(
|
||||||
withTestAccountFlag({
|
withTestAccountFlag({
|
||||||
identityToken,
|
identityToken,
|
||||||
platform: WEB_PLATFORM,
|
platform: getAuthPlatform(),
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -319,3 +317,7 @@ function withTestAccountFlag<T extends Record<string, unknown>>(
|
|||||||
[TEST_ACCOUNT_FLAG]: !AppEnvUtil.isProduction(),
|
[TEST_ACCOUNT_FLAG]: !AppEnvUtil.isProduction(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getAuthPlatform(): string {
|
||||||
|
return PlatformDetector.getPlatform();
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,11 +2,6 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* IUserRepository 接口
|
* IUserRepository 接口
|
||||||
*
|
|
||||||
* 对齐 Dart 端 `UserRepository` 抽象(lib/data/repositories/user_repository.dart):
|
|
||||||
* - 纯远程调用,不直接写本地 storage(持久化由 AuthRepository 在登录流程中处理)
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { Result } from "@/utils";
|
import type { Result } from "@/utils";
|
||||||
|
|||||||
Reference in New Issue
Block a user