Cloud Flare Context is not defined when using Session
Im getting this message every time i try to call a server action that calls useSession hook
it only happens on CloudFlare preset builds. On preset cloudflare-modules
the error is
Uncaught (in promise) Error: Context is not availableUncaught (in promise) Error: Context is not availableit only happens on CloudFlare preset builds. On preset cloudflare-modules
the error is
SES_UNHANDLED_REJECTION: Error: Context is not availableSES_UNHANDLED_REJECTION: Error: Context is not availableimport { useSession } from 'vinxi/http';
export interface UserSession {
id: number;
}
function getSession() {
'use server';
return useSession<UserSession>({
password: process.env.SESSION_SECRET!
});
}
export async function getSessionData() {
'use server';
const session = await getSession();
if (!session.data.id) {
return null;
}
return session.data;
}
export async function login() {
'use server';
const session = await getSession();
await session.update(() => ({
id: 1
}));
return session.data;
}
export async function logout() {
'use server';
const session = await getSession();
await session.clear();
}import { useSession } from 'vinxi/http';
export interface UserSession {
id: number;
}
function getSession() {
'use server';
return useSession<UserSession>({
password: process.env.SESSION_SECRET!
});
}
export async function getSessionData() {
'use server';
const session = await getSession();
if (!session.data.id) {
return null;
}
return session.data;
}
export async function login() {
'use server';
const session = await getSession();
await session.update(() => ({
id: 1
}));
return session.data;
}
export async function logout() {
'use server';
const session = await getSession();
await session.clear();
}
