feat: verify oidc bearer tokens and jit-provision users

This commit is contained in:
Bastian Wagner
2026-08-17 14:54:42 +02:00
parent 7ca4bd9cf7
commit 5abc7cbe29
14 changed files with 294 additions and 11 deletions

View File

@@ -2,7 +2,7 @@ import { Inject, Injectable } from '@nestjs/common';
import type { Kysely } from 'kysely';
import { KYSELY_DB } from '../../database/src';
import type { Database } from '../../database/src';
import type { UpdateUserPreferenceDto, UserPreference } from './user.types';
import type { UserPreference, UserPreferenceFields } from './user.types';
function toUserPreference(row: {
user_id: string;
@@ -44,23 +44,25 @@ export class UserPreferencesRepository {
async upsert(
userId: string,
dto: UpdateUserPreferenceDto,
fields: UserPreferenceFields,
): Promise<UserPreference> {
const values = {
preferred_pace: dto.preferredPace,
preferred_budget_level: dto.preferredBudgetLevel,
max_walking_distance_km: dto.maxWalkingDistanceKm ?? null,
preferred_start_time: dto.preferredStartTime,
child_friendly_preferred: dto.childFriendlyPreferred,
interests: dto.interests,
notes: dto.notes,
preferred_pace: fields.preferredPace,
preferred_budget_level: fields.preferredBudgetLevel,
max_walking_distance_km: fields.maxWalkingDistanceKm,
preferred_start_time: fields.preferredStartTime,
child_friendly_preferred: fields.childFriendlyPreferred,
interests: fields.interests,
notes: fields.notes,
};
const row = await this.db
.insertInto('user_preferences')
.values({ user_id: userId, ...values })
.onConflict((oc) =>
oc.column('user_id').doUpdateSet({ ...values, updated_at: new Date() }),
oc
.column('user_id')
.doUpdateSet({ ...values, updated_at: new Date().toISOString() }),
)
.returningAll()
.executeTakeFirstOrThrow();

View File

@@ -33,6 +33,9 @@ export interface UpdateUserPreferenceDto {
notes?: string | null;
}
/** Fully-resolved preference fields (no optional/undefined members) ready to persist. */
export type UserPreferenceFields = Omit<UserPreference, 'userId'>;
export const DEFAULT_USER_PREFERENCE: Omit<UserPreference, 'userId'> = {
preferredPace: null,
preferredBudgetLevel: null,

View File

@@ -41,7 +41,7 @@ export class UsersRepository {
oc.column('external_subject_id').doUpdateSet({
display_name: claims.displayName,
email: claims.email,
updated_at: new Date(),
updated_at: new Date().toISOString(),
}),
)
.returningAll()