feat(auth): add Messenger topup handoff entry
Docker Image / Build and Push Docker Image (push) Successful in 2m9s
Docker Image / Build and Push Docker Image (push) Successful in 2m9s
This commit is contained in:
@@ -3,18 +3,17 @@ import type { IAuthRepository } from "@/data/repositories/interfaces";
|
||||
import {
|
||||
FacebookIdentityRequestSchema,
|
||||
FacebookLoginRequestSchema,
|
||||
FacebookPsidLoginRequestSchema,
|
||||
FbIdLoginRequestSchema,
|
||||
GoogleLoginRequestSchema,
|
||||
GuestLoginRequestSchema,
|
||||
GuestLoginResponse,
|
||||
LoginRequestSchema,
|
||||
LoginResponse,
|
||||
LoginResponseSchema,
|
||||
LoginStatus,
|
||||
RefreshTokenRequestSchema,
|
||||
RefreshTokenResponse,
|
||||
RegisterRequestSchema,
|
||||
TopUpHandoffRequestSchema,
|
||||
type LoginStatus as LoginStatusT,
|
||||
} from "@/data/schemas/auth";
|
||||
import { User } from "@/data/schemas/user";
|
||||
@@ -264,54 +263,16 @@ export class AuthRepository implements IAuthRepository {
|
||||
});
|
||||
}
|
||||
|
||||
/** 通过 Facebook PSID 直接登录或返回游客态。 */
|
||||
async facebookPsidLogin(input: {
|
||||
psid: string;
|
||||
deviceId?: string;
|
||||
bindToGuest?: boolean;
|
||||
}): Promise<Result<LoginStatusT>> {
|
||||
/** 消费一次性充值凭证并按后端返回的 canonical 账号建立正式会话。 */
|
||||
async consumeTopUpHandoff(
|
||||
handoffToken: string,
|
||||
): Promise<Result<LoginStatusT>> {
|
||||
return Result.wrap(async () => {
|
||||
const response = await this.api.facebookPsidLogin(
|
||||
FacebookPsidLoginRequestSchema.parse({
|
||||
psid: input.psid,
|
||||
deviceId: input.deviceId ?? "",
|
||||
bindToGuest: input.bindToGuest ?? true,
|
||||
}),
|
||||
const response = await this.api.consumeTopUpHandoff(
|
||||
TopUpHandoffRequestSchema.parse({ handoffToken }),
|
||||
);
|
||||
const data = response;
|
||||
await this._saveFacebookIdentity({
|
||||
asid: data.fbAsid,
|
||||
psid: data.fbPsid,
|
||||
});
|
||||
|
||||
if (data.isGuest || !data.hasCompleteFacebookIdentity) {
|
||||
const tokenResult = await this.storage.setGuestToken(data.token);
|
||||
if (Result.isErr(tokenResult)) throw tokenResult.error;
|
||||
if (input.deviceId) {
|
||||
const deviceResult = await this.storage.setDeviceId(input.deviceId);
|
||||
if (Result.isErr(deviceResult)) throw deviceResult.error;
|
||||
}
|
||||
const userId = data.userId || data.user?.id || "";
|
||||
if (userId) {
|
||||
const userIdResult = await this.userStorage.setUserId(userId);
|
||||
if (Result.isErr(userIdResult)) throw userIdResult.error;
|
||||
}
|
||||
const providerResult = await this.storage.setLoginProvider(
|
||||
LoginStatus.Guest,
|
||||
);
|
||||
if (Result.isErr(providerResult)) throw providerResult.error;
|
||||
return LoginStatus.Guest;
|
||||
}
|
||||
|
||||
await this._saveLoginData(
|
||||
LoginResponseSchema.parse({
|
||||
token: data.token,
|
||||
refreshToken: data.refreshToken,
|
||||
user: data.user ?? { id: data.userId },
|
||||
}),
|
||||
LoginStatus.Facebook,
|
||||
);
|
||||
return LoginStatus.Facebook;
|
||||
await this._saveLoginData(response, response.loginStatus);
|
||||
return response.loginStatus;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user