better-auth
Version:
The most comprehensive authentication library for TypeScript.
101 lines (98 loc) • 3.23 kB
JavaScript
import * as z from 'zod/v4';
import 'better-call';
import { j as createAuthEndpoint, m as getSession } from '../../shared/better-auth.z3dsxLxE.mjs';
import '../../shared/better-auth.8zoxzg-F.mjs';
import '@better-auth/utils/base64';
import '@better-auth/utils/hmac';
import '@better-auth/utils/binary';
import '../../shared/better-auth.n2KFGwjY.mjs';
import '../../shared/better-auth.DBGfIDnh.mjs';
import 'defu';
import '../../shared/better-auth.CW6D9eSx.mjs';
import '@better-auth/utils/hash';
import '../../crypto/index.mjs';
import '@noble/ciphers/chacha';
import '@noble/ciphers/utils';
import '@noble/ciphers/webcrypto';
import 'jose';
import '@noble/hashes/scrypt';
import '@better-auth/utils';
import '@better-auth/utils/hex';
import '@noble/hashes/utils';
import '../../shared/better-auth.B4Qoxdgc.mjs';
import '@better-auth/utils/random';
import '@better-fetch/fetch';
import '../../shared/better-auth.VTXNLFMT.mjs';
import '../../shared/better-auth.DdzSJf-n.mjs';
import '../../cookies/index.mjs';
import '../../shared/better-auth.tB5eU6EY.mjs';
import 'jose/errors';
const customSession = (fn, options) => {
return {
id: "custom-session",
endpoints: {
getSession: createAuthEndpoint(
"/get-session",
{
method: "GET",
query: z.optional(
z.object({
/**
* If cookie cache is enabled, it will disable the cache
* and fetch the session from the database
*/
disableCookieCache: z.boolean().meta({
description: "Disable cookie cache and fetch session from database"
}).or(z.string().transform((v) => v === "true")).optional(),
disableRefresh: z.boolean().meta({
description: "Disable session refresh. Useful for checking session status, without updating the session"
}).optional()
})
),
metadata: {
CUSTOM_SESSION: true,
openapi: {
description: "Get custom session data",
responses: {
"200": {
description: "Success",
content: {
"application/json": {
schema: {
type: "array",
nullable: true,
items: {
$ref: "#/components/schemas/Session"
}
}
}
}
}
}
}
},
requireHeaders: true
},
async (ctx) => {
const session = await getSession()({
...ctx,
asResponse: false,
headers: ctx.headers,
returnHeaders: true
}).catch((e) => {
return null;
});
if (!session?.response) {
return ctx.json(null);
}
const fnResult = await fn(session.response, ctx);
session.headers.forEach((value, key) => {
ctx.setHeader(key, value);
});
return ctx.json(fnResult);
}
)
}
};
};
export { customSession };