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

36 lines
1.0 KiB
TypeScript
Raw Normal View History

2026-03-09 11:18:22 +01:00
import { getOrgBySiteName } from '$features/org/api/org.server';
import { classroomio } from '$lib/utils/services/api';
import { getApiKeyHeaders } from '$lib/utils/services/api/server';
import { redirect } from '@sveltejs/kit';
export const load = async ({ params = { hash: '' } }) => {
try {
2026-03-09 11:18:22 +01:00
const token = decodeURIComponent(params.hash);
const response = await classroomio.invite.organization[':token'].preview.$get(
{
param: { token }
},
getApiKeyHeaders()
);
const result = await response.json();
2026-03-09 11:18:22 +01:00
if (!result.success || !result.data) {
throw new Error('Invalid organization invite payload');
}
2026-03-09 11:18:22 +01:00
const apiKeyHeaders = getApiKeyHeaders();
const currentOrg = result.data.organization.siteName
? await getOrgBySiteName(result.data.organization.siteName, apiKeyHeaders)
: null;
return {
2026-03-09 11:18:22 +01:00
token,
invite: result.data,
currentOrg
};
} catch (error) {
2026-03-09 11:18:22 +01:00
console.error('Error decoding organization invite params.hash', error);
2025-11-01 15:49:29 +01:00
redirect(307, '/404');
}
};