25 lines
722 B
TypeScript
25 lines
722 B
TypeScript
import { fail, redirect } from '@sveltejs/kit';
|
|
import { setDeviceTokenCookie } from '$lib/server/auth';
|
|
import { PROXY_URL } from '$app/env/public';
|
|
|
|
const HONO_URL = PROXY_URL;
|
|
|
|
export const actions = {
|
|
default: async (event) => {
|
|
const code = event.params.code;
|
|
const name = event.params.member;
|
|
|
|
const res = await fetch(`${HONO_URL}/api/members/direct-join`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ inviteCode: code, name }),
|
|
});
|
|
const data = await res.json();
|
|
if (!res.ok) return fail(400, { error: data.error || 'Join failed' });
|
|
|
|
setDeviceTokenCookie(event, data.deviceToken);
|
|
|
|
throw redirect(303, `/${data.famSlug}/${data.name}`);
|
|
},
|
|
};
|