Skip to content

Commit 8a5862e

Browse files
committed
chore: fix type error
1 parent 40014b2 commit 8a5862e

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

packages/core/src/auth/context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export type AuthContext<TConfig extends AuthConfig = AuthConfig> = {
2626
authConfig: TConfig
2727
internalHandlers: InternalHandlers
2828

29-
requiredAuthenticated: (headers: Record<string, string>) => Promise<InferTableType<AnyUserTable>>
29+
requiredAuthenticated: (headers?: Record<string, string>) => Promise<InferTableType<AnyUserTable>>
3030
}
3131

3232
export function createAuthContext<TAuthConfig extends AuthConfig, TContext extends MinimalContext>(
@@ -39,7 +39,7 @@ export function createAuthContext<TAuthConfig extends AuthConfig, TContext exten
3939
authConfig: authConfig,
4040
internalHandlers: internalHandlers,
4141

42-
requiredAuthenticated: async (headers: Record<string, string>) => {
42+
requiredAuthenticated: async (headers?: Record<string, string>) => {
4343
const sessionId = getSessionCookie(headers)
4444
if (!sessionId) throw new Error('Unauthorized')
4545
const session = await internalHandlers.session.findUserBySessionId(sessionId)

packages/core/src/auth/utils.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
function setCookie(headers: Record<string, string>, name: string, value: string) {
1+
function setCookie(headers: Record<string, string> | undefined, name: string, value: string) {
2+
if (!headers) return
23
headers['Set-Cookie'] = `${name}=${value}; Path=/; HttpOnly; SameSite=Strict`
34
}
45

5-
function getCookie(headers: Record<string, string>, name: string) {
6+
function getCookie(headers: Record<string, string> | undefined, name: string) {
7+
if (!headers) return null
68
const cookie = headers[name]
79
if (!cookie) return null
810
const cookies = cookie.split('; ')
@@ -13,20 +15,21 @@ function getCookie(headers: Record<string, string>, name: string) {
1315
return null
1416
}
1517

16-
function deleteCookie(headers: Record<string, string>, name: string) {
18+
function deleteCookie(headers: Record<string, string> | undefined, name: string) {
19+
if (!headers) return
1720
headers['Set-Cookie'] = `${name}=; Path=/; HttpOnly; SameSite=Strict; Max-Age=0`
1821
}
1922

2023
const SESSION_COOKIE_NAME = 'SESSION_ID'
2124

22-
export function getSessionCookie(headers: Record<string, string>) {
25+
export function getSessionCookie(headers: Record<string, string> | undefined) {
2326
return getCookie(headers, SESSION_COOKIE_NAME)
2427
}
2528

26-
export function setSessionCookie(headers: Record<string, string>, value: string) {
29+
export function setSessionCookie(headers: Record<string, string> | undefined, value: string) {
2730
setCookie(headers, SESSION_COOKIE_NAME, value)
2831
}
2932

30-
export function deleteSessionCookie(headers: Record<string, string>) {
33+
export function deleteSessionCookie(headers?: Record<string, string>) {
3134
deleteCookie(headers, SESSION_COOKIE_NAME)
3235
}

0 commit comments

Comments
 (0)