Files
classroomio/apps/dashboard/src/routes/invite/[hash]/+layout.server.ts
T

40 lines
1.3 KiB
TypeScript
Raw Normal View History

2026-03-09 11:18:22 +01:00
import { getOrgBySiteName } from '$features/org/api/org.server';
import { classroomio, type InferResponseType } from '$lib/utils/services/api';
import { getApiKeyHeaders, safeServerApi } from '$lib/utils/services/api/server';
import { error } from '@sveltejs/kit';
type PreviewOrganizationInviteRequest = (typeof classroomio.invite.organization)[':token']['preview']['$get'];
type PreviewOrganizationInviteSuccess = Extract<InferResponseType<PreviewOrganizationInviteRequest>, { success: true }>;
export const load = async ({ params = { hash: '' } }) => {
try {
2026-03-09 11:18:22 +01:00
const token = decodeURIComponent(params.hash);
const result = await safeServerApi<PreviewOrganizationInviteSuccess>(() =>
classroomio.invite.organization[':token'].preview.$get(
{
param: { token }
},
getApiKeyHeaders()
)
2026-03-09 11:18:22 +01:00
);
if (!result.ok || !result.body.data) {
2026-03-09 11:18:22 +01:00
throw new Error('Invalid organization invite payload');
}
2026-03-09 11:18:22 +01:00
const apiKeyHeaders = getApiKeyHeaders();
const currentOrg = result.body.data.organization.siteName
? await getOrgBySiteName(result.body.data.organization.siteName, apiKeyHeaders)
2026-03-09 11:18:22 +01:00
: null;
return {
2026-03-09 11:18:22 +01:00
token,
invite: result.body.data,
2026-03-09 11:18:22 +01:00
currentOrg
};
} catch (e) {
console.error('Error decoding organization invite params.hash', e);
throw error(404, 'Not found');
}
};