Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(session): remove unnecessary async for clear #729

Merged
merged 4 commits into from
Apr 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/utils/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ export async function useSession<T extends SessionDataT = SessionDataT>(
await updateSession<T>(event, config, update);
return sessionManager;
},
clear: async () => {
await clearSession(event, config);
return sessionManager;
clear: () => {
clearSession(event, config);
return Promise.resolve(sessionManager);
},
};
return sessionManager;
Expand Down Expand Up @@ -234,16 +234,17 @@ export async function unsealSession(
/**
* Clear the session data for the current request.
*/
export async function clearSession(
export function clearSession(
event: H3Event,
config: Partial<SessionConfig>,
) {
): Promise<void> {
const sessionName = config.name || DEFAULT_NAME;
if (event.context.sessions?.[sessionName]) {
delete event.context.sessions![sessionName];
}
await setCookie(event, sessionName, "", {
setCookie(event, sessionName, "", {
...DEFAULT_COOKIE,
...config.cookie,
});
return Promise.resolve();
}