refactor(auth): inline NextAuth v4 config and simplify AuthPlatform API
- Inline NextAuth v4 handler directly in `[...nextauth]/route.ts`, removing
the `@/lib/auth/nextauth` abstraction layer
- Add Google/Facebook providers with JWT/session callbacks that expose
`idToken` and `accessToken` on the session for backend exchange
- Refactor `AuthPlatform` from constructor-based to static methods
(`googleSignIn()` / `facebookSignIn()`)
- Update `auth-machine.ts` and layout comment reference to match new structure
- Align with original Dart `nextauth-helpers.{googleLogin, facebookLogin}()`
naming and keep persistence concerns (unstorage, backend, custom cookies)
out of scope for this iteration
This commit is contained in:
@@ -9,9 +9,8 @@
|
||||
* `next-auth/react.signIn`(OAuth 跳转)。
|
||||
*/
|
||||
import { setup, fromPromise, assign } from "xstate";
|
||||
import { signIn } from "next-auth/react";
|
||||
|
||||
import type { AuthProvider } from "@/lib/auth/auth_platform";
|
||||
import { AuthPlatform, type AuthProvider } from "@/lib/auth/auth_platform";
|
||||
import type { LoginStatus } from "@/models/auth/login-status";
|
||||
import { authRepository } from "@/data/repositories/auth_repository";
|
||||
import type { IAuthRepository } from "@/data/repositories/interfaces";
|
||||
@@ -72,11 +71,15 @@ const emailRegisterThenLoginActor = fromPromise<
|
||||
return "email" as LoginStatus;
|
||||
});
|
||||
|
||||
// OAuth 登录 actor:调 next-auth/react 的 signIn(provider) 触发 OAuth 跳转。
|
||||
// OAuth 登录 actor:调 AuthPlatform 触发 OAuth 跳转。
|
||||
// 成功路径下 NextAuth 会重定向离开本应用,actor 通常不会 resolve;
|
||||
// onDone 仍保留以处理 SDK 同步返回(极少见)。
|
||||
const oauthSignInActor = fromPromise<void, AuthProvider>(async ({ input }) => {
|
||||
await signIn(input);
|
||||
if (input === "google") {
|
||||
await AuthPlatform.googleSignIn();
|
||||
} else {
|
||||
await AuthPlatform.facebookSignIn();
|
||||
}
|
||||
});
|
||||
|
||||
// ========== OAuth token → 后端业务 token sync actors ==========
|
||||
|
||||
Reference in New Issue
Block a user