Changeset 6196d60


Ignore:
Timestamp:
12/24/25 00:34:57 (7 months ago)
Author:
Tome <gjorgievtome@…>
Branches:
main
Children:
40ac7a9
Parents:
ea09e98
Message:

Modify getAuthState()

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pages/+Layout.telefunc.ts

    rea09e98 r6196d60  
    11import * as drizzleQueries from "../database/drizzle/queries";
    2 import {ctx, getAuthState, requireUser} from "../server/telefunc/ctx";
     2import {ctx, getAuthState, parseSessionUserId, requireUser} from "../server/telefunc/ctx";
    33import {Abort} from "telefunc";
    44import type {Database} from "../database/drizzle/db";
     
    6565export async function onGetBuildDetails({ buildId }
    6666                                           : { buildId: number }) {
    67     const context = getAuthState();
     67    const context = ctx();
    6868
    6969    if(!Number.isInteger(buildId) || buildId <= 0) throw Abort();
    7070
    71     const buildDetails = await drizzleQueries.getBuildDetails(context.db, buildId, context.userId ?? undefined);
     71    const userId = parseSessionUserId(context.session?.user?.id);
     72    const buildDetails = await drizzleQueries.getBuildDetails(context.db, buildId, userId);
    7273
    7374    if(!buildDetails) throw Abort();
  • server/telefunc/ctx.ts

    rea09e98 r6196d60  
    66}
    77
    8 export function parseSessionUserId(sessionUserId: unknown): number | null {
    9     if (typeof sessionUserId !== "string" && typeof sessionUserId !== "number") return null;
     8export function parseSessionUserId(sessionUserId: unknown): number | undefined {
     9    if (typeof sessionUserId !== "string" && typeof sessionUserId !== "number") return undefined;
    1010    const n = Number(sessionUserId);
    11     return Number.isInteger(n) && n > 0 ? n : null;
     11    return Number.isInteger(n) && n > 0 ? n : undefined;
    1212}
    1313
     
    2727        username: c.session?.user?.name ?? null,
    2828        session: c.session,
    29         db: c.db,
    3029    };
    3130}
Note: See TracChangeset for help on using the changeset viewer.