Skip to content

Explicit Return Type on getUserSession #379

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

Merged
merged 3 commits into from
Apr 7, 2025
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
8 changes: 4 additions & 4 deletions src/runtime/server/utils/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const sessionHooks = createHooks<SessionHooks>()
* @param event The Request (h3) event
* @returns The user session
*/
export async function getUserSession(event: UseSessionEvent) {
export async function getUserSession(event: UseSessionEvent): Promise<UserSession> {
const session = await _useSession(event)
return {
id: session.id,
Expand All @@ -40,7 +40,7 @@ export async function getUserSession(event: UseSessionEvent) {
* @param data User session data, please only store public information since it can be decoded with API calls
* @see https://github.com/atinux/nuxt-auth-utils
*/
export async function setUserSession(event: H3Event, data: UserSession, config?: Partial<SessionConfig>) {
export async function setUserSession(event: H3Event, data: UserSession, config?: Partial<SessionConfig>): Promise<UserSession> {
const session = await _useSession(event, config)

await session.update(defu(data, session.data))
Expand All @@ -53,7 +53,7 @@ export async function setUserSession(event: H3Event, data: UserSession, config?:
* @param event The Request (h3) event
* @param data User session data, please only store public information since it can be decoded with API calls
*/
export async function replaceUserSession(event: H3Event, data: UserSession, config?: Partial<SessionConfig>) {
export async function replaceUserSession(event: H3Event, data: UserSession, config?: Partial<SessionConfig>): Promise<UserSession> {
const session = await _useSession(event, config)

await session.clear()
Expand All @@ -67,7 +67,7 @@ export async function replaceUserSession(event: H3Event, data: UserSession, conf
* @param event The Request (h3) event
* @returns true if the session was cleared
*/
export async function clearUserSession(event: H3Event, config?: Partial<SessionConfig>) {
export async function clearUserSession(event: H3Event, config?: Partial<SessionConfig>): Promise<boolean> {
const session = await _useSession(event, config)

await sessionHooks.callHookParallel('clear', session.data, event)
Expand Down