Weird error when calling new User(...)
#320
-
|
Hi again! I am working on SSR auth for The basic idea is the following import type { Handle } from '@sveltejs/kit';
import PocketBase, { User } from 'pocketbase';
import cookie from 'cookie';
export const handle: Handle = async ({ event, resolve }) => {
const client = new PocketBase('http://127.0.0.1:8090');
event.locals.pocketbase = client;
const { token, user } = cookie.parse(event.request.headers.get('Cookie') ?? '');
if (!token || !user) {
return await resolve(event);
}
client.authStore.save(token, new User(JSON.parse(user)));
return await resolve(event);
};then you would set these cookies, which stores the token/user, in other endpoints like The problem here is: client.authStore.save(token, new User(JSON.parse(user)));I wanted to However, that results in: First I thought that I might have messed up something else, so I created a StackBlitz where I:
But I still get: The StackBlitz can be found here: Now for the question, is this expected (maybe this is basic js and I just don't understand why this shouldn't work)? If this is not expected, is this something that is reproducible for other frameworks or related to Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
For some reason when in SSR mode vite seems to use the commonjs bundle even though:
I'm not sure if this is a bug with Vite or something with my packaging. I'll try to find time to investigate it tomorrow. As a workaround for now you can reference directly the es bundle: import { User } from '../node_modules/pocketbase/dist/pocketbase.es.mjs'; |
Beta Was this translation helpful? Give feedback.
For some reason when in SSR mode vite seems to use the commonjs bundle even though:
type:"module"in your package.json.mjsextension - https://github.com/pocketbase/js-sdk/blob/master/package.json#L12.I'm not sure if this is a bug with Vite or something with my packaging. I'll try to find time to investigate it tomorrow. As a workaround for now you can reference directly the es bundle: