Browse Source

refactor: simplify user authentication handling in me.get.ts

Replace session ID retrieval and validation logic with a direct call to requireUser() for improved clarity and efficiency in user authentication. This change streamlines the error handling process by ensuring that session cookies are cleared only when necessary.
main
npmrun 8 hours ago
parent
commit
3df618d552
  1. 11
      server/api/auth/me.get.ts

11
server/api/auth/me.get.ts

@ -4,16 +4,7 @@ import { toPublicAuthError } from "#server/service/auth/errors";
export default defineWrappedResponseHandler(async (event) => {
try {
const sessionId = getSessionId(event);
if (!sessionId) {
clearSessionCookie(event);
throw createError({
statusCode: 401,
statusMessage: UNAUTHORIZED_MESSAGE,
});
}
const user = await event.context.auth.getCurrent();
const user = await event.context.auth.requireUser();
if (!user) {
clearSessionCookie(event);
throw createError({

Loading…
Cancel
Save