@instantdb/core 0.22.90-experimental.drewh-ssr.20312174628.1 → 0.22.90-experimental.drewh-ssr.20347747146.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instantdb/core",
3
- "version": "0.22.90-experimental.drewh-ssr.20312174628.1",
3
+ "version": "0.22.90-experimental.drewh-ssr.20347747146.1",
4
4
  "description": "Instant's core local abstraction",
5
5
  "homepage": "https://github.com/instantdb/instant/tree/main/client/packages/core",
6
6
  "repository": {
@@ -53,7 +53,7 @@
53
53
  "dependencies": {
54
54
  "mutative": "^1.0.10",
55
55
  "uuid": "^11.1.0",
56
- "@instantdb/version": "0.22.90-experimental.drewh-ssr.20312174628.1"
56
+ "@instantdb/version": "0.22.90-experimental.drewh-ssr.20347747146.1"
57
57
  },
58
58
  "scripts": {
59
59
  "test": "vitest",
package/src/Reactor.js CHANGED
@@ -2048,11 +2048,13 @@ export default class Reactor {
2048
2048
  }
2049
2049
 
2050
2050
  async syncUserToEndpoint(user) {
2051
- if (this.config.cookieEndpoint) {
2051
+ if (this.config.firstPartyPath) {
2052
2052
  try {
2053
- fetch(this.config.cookieEndpoint + '/sync-auth', {
2053
+ fetch(this.config.firstPartyPath + '/', {
2054
2054
  method: 'POST',
2055
2055
  body: JSON.stringify({
2056
+ type: 'sync-user',
2057
+ appId: this.config.appId,
2056
2058
  user: user,
2057
2059
  }),
2058
2060
  headers: {
@@ -1,44 +1,56 @@
1
- export const createInstantRouteHandler = (config: {
2
- appId: string;
3
- apiURI?: string;
4
- }) => {
5
- async function handleUserSync(req: Request) {
6
- const body = await req.json();
7
- if (body.user && body.user.refresh_token) {
8
- return new Response('sync', {
1
+ import type { User } from './clientTypes.js';
2
+
3
+ export const createInstantRouteHandler = (config: { appId: string }) => {
4
+ function createUserSyncResponse(user: User | null) {
5
+ if (user && user.refresh_token) {
6
+ return new Response(JSON.stringify({ ok: true }), {
9
7
  headers: {
8
+ 'Content-Type': 'application/json',
10
9
  // 7 day expiry
11
- 'Set-Cookie': `instant_user=${JSON.stringify(body.user)}; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=604800`,
10
+ 'Set-Cookie': `instant_user_${config.appId}=${JSON.stringify(user)}; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=604800`,
12
11
  },
13
12
  });
14
13
  } else {
15
- return new Response('sync', {
14
+ return new Response(JSON.stringify({ ok: true }), {
16
15
  headers: {
16
+ 'Content-Type': 'application/json',
17
17
  // remove the cookie (some browsers)
18
- 'Set-Cookie': `instant_user=; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=-1`,
18
+ 'Set-Cookie': `instant_user_${config.appId}=; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=-1`,
19
19
  },
20
20
  });
21
21
  }
22
22
  }
23
23
 
24
+ function errorResponse(status: number, message: string) {
25
+ return new Response(JSON.stringify({ ok: false, error: message }), {
26
+ status,
27
+ headers: { 'Content-Type': 'application/json' },
28
+ });
29
+ }
30
+
24
31
  return {
25
- GET: async (_req: Request) => {
26
- return new Response('Method not allowed', {
27
- status: 405,
28
- statusText: 'Method Not Allowed',
29
- });
30
- },
31
32
  POST: async (req: Request) => {
32
- const url = new URL(req.url);
33
- const pathname = url.pathname;
34
- const route = pathname.split('/')[pathname.split('/').length - 1];
35
- switch (route) {
36
- case 'sync-auth':
37
- return await handleUserSync(req);
33
+ let body: { type?: string; appId?: string; user?: User | null };
34
+ try {
35
+ body = await req.json();
36
+ } catch {
37
+ return errorResponse(400, 'Invalid JSON body');
38
+ }
39
+
40
+ if (!body.type) {
41
+ return errorResponse(400, 'Missing "type" field');
42
+ }
43
+
44
+ if (body.appId !== config.appId) {
45
+ return errorResponse(403, 'App ID mismatch');
46
+ }
47
+
48
+ switch (body.type) {
49
+ case 'sync-user':
50
+ return createUserSyncResponse(body.user ?? null);
51
+ default:
52
+ return errorResponse(400, `Unknown type: ${body.type}`);
38
53
  }
39
- return new Response('Route not found', {
40
- status: 404,
41
- });
42
54
  },
43
55
  };
44
56
  };
package/src/framework.ts CHANGED
@@ -134,6 +134,7 @@ export class FrameworkClient {
134
134
  entry.error = error;
135
135
  entry.promise = null;
136
136
  });
137
+ this.resultMap.set(hash, entry);
137
138
  return entry as any;
138
139
  }
139
140
 
package/src/index.ts CHANGED
@@ -157,7 +157,7 @@ export type InstantConfig<
157
157
  appId: string;
158
158
  schema?: S;
159
159
  websocketURI?: string;
160
- cookieEndpoint?: string;
160
+ firstPartyPath?: string;
161
161
  apiURI?: string;
162
162
  devtool?: boolean | DevtoolConfig;
163
163
  verbose?: boolean;