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';
|
2025-12-02 09:54:38 +01:00
|
|
|
import { redirect } from '@sveltejs/kit';
|
2023-09-14 06:42:16 +01:00
|
|
|
|
2023-09-01 15:28:47 +01:00
|
|
|
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();
|
2023-09-01 15:28:47 +01:00
|
|
|
|
2026-03-09 11:18:22 +01:00
|
|
|
if (!result.success || !result.data) {
|
|
|
|
|
throw new Error('Invalid organization invite payload');
|
|
|
|
|
}
|
2023-09-01 15:28:47 +01:00
|
|
|
|
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;
|
2023-09-14 06:42:16 +01:00
|
|
|
|
2023-09-01 15:28:47 +01:00
|
|
|
return {
|
2026-03-09 11:18:22 +01:00
|
|
|
token,
|
|
|
|
|
invite: result.data,
|
|
|
|
|
currentOrg
|
2023-09-01 15:28:47 +01:00
|
|
|
};
|
|
|
|
|
} 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');
|
2023-09-01 15:28:47 +01:00
|
|
|
}
|
|
|
|
|
};
|