feat: support custom cookie options

This commit is contained in:
Aarnav Tale
2025-11-02 14:04:38 -05:00
parent ce4be73faf
commit b1c93512df
5 changed files with 17 additions and 3 deletions
+4
View File
@@ -23,6 +23,8 @@ const serverConfig = type({
cookie_secret: '(32 <= string <= 32)?',
cookie_secret_path: 'string?',
cookie_secure: stringToBool,
cookie_domain: 'string?',
cookie_max_age: 'number.integer = 86400',
})
.narrow((obj: Record<string, unknown>, ctx: any) => {
const hasVal = obj.cookie_secret != null && `${obj.cookie_secret}` !== '';
@@ -49,6 +51,8 @@ const partialServerConfig = type({
cookie_secret: '32 <= string <= 32?',
cookie_secret_path: 'string?',
cookie_secure: stringToBool.optional(),
cookie_domain: 'string?',
cookie_max_age: 'number.integer?',
});
const oidcConfig = type({
+2 -2
View File
@@ -62,8 +62,8 @@ const appLoadContext = {
cookie: {
name: '_hp_auth',
secure: config.server.cookie_secure,
maxAge: 60 * 60 * 24, // 24 hours
// domain: config.server.cookie_domain,
maxAge: config.server.cookie_max_age,
domain: config.server.cookie_domain,
},
}),
+2 -1
View File
@@ -152,13 +152,14 @@ class Sessionizer {
}
async function createSession(payload: JWTSession, options: AuthSessionOptions) {
const now = Math.floor(Date.now() / 1000);
const secret = createHash('sha256').update(options.secret, 'utf8').digest();
const jwt = await new EncryptJWT({
...payload,
})
.setProtectedHeader({ alg: 'dir', enc: 'A256GCM', typ: 'JWT' })
.setIssuedAt()
.setExpirationTime('1d')
.setExpirationTime(now + options.cookie.maxAge)
.setIssuer('urn:tale:headplane')
.setAudience('urn:tale:headplane')
.setJti(ulid())