Browse Source
- Added `ensureClientMeSynced` function to synchronize client session with server, improving user experience by reducing unnecessary API calls. - Updated `AppShell`, `public.vue`, and other components to utilize the new synchronization method instead of the previous refresh mechanism. - Introduced a new API endpoint for session handling, ensuring consistent user state across client and server. - Refactored `useAuthSession` to manage client session state more effectively, enhancing overall authentication flow. This update streamlines the authentication process and enhances the reliability of user session management.main
11 changed files with 50 additions and 24 deletions
Binary file not shown.
@ -0,0 +1,14 @@ |
|||||
|
import { toPublicAuthError } from "#server/service/auth/errors"; |
||||
|
|
||||
|
/** |
||||
|
* 客户端对齐用:无会话 Cookie 时不访问数据库;有 Cookie 时与 SSR `auth.getCurrent()` 同路径。 |
||||
|
* 始终 200 + `{ user }`,不向未登录客户端抛 401(与 `/api/auth/me` 区分)。 |
||||
|
*/ |
||||
|
export default defineWrappedResponseHandler(async (event) => { |
||||
|
try { |
||||
|
const user = await event.context.auth.getCurrent(); |
||||
|
return R.success({ user: user ?? null }); |
||||
|
} catch (err) { |
||||
|
throw toPublicAuthError(err); |
||||
|
} |
||||
|
}); |
||||
Loading…
Reference in new issue