You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

47 lines
855 B

import type { PageServerLoad } from './$types';
export const load: PageServerLoad = async ({ params, locals }) => {
const { token } = params;
// Get invite details
const { data: invite, error } = await locals.supabase
.from('org_invites')
.select(`
*,
organizations (id, name, slug)
`)
.eq('token', token)
.is('accepted_at', null)
.single();
if (error || !invite) {
return {
error: 'Invalid or expired invite link',
token
};
}
const inv = invite as any;
// Check if invite is expired
if (new Date(inv.expires_at) < new Date()) {
return {
error: 'This invite has expired',
token
};
}
// Get current user
const { data: { user } } = await locals.supabase.auth.getUser();
return {
invite: {
id: inv.id,
email: inv.email,
role: inv.role,
org: inv.organizations
},
user,
token
};
};