prostgles-server 4.2.270 → 4.2.272

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.
Files changed (67) hide show
  1. package/dist/Auth/AuthHandler.d.ts +15 -8
  2. package/dist/Auth/AuthHandler.d.ts.map +1 -1
  3. package/dist/Auth/AuthHandler.js +34 -58
  4. package/dist/Auth/AuthHandler.js.map +1 -1
  5. package/dist/Auth/AuthTypes.d.ts +12 -2
  6. package/dist/Auth/AuthTypes.d.ts.map +1 -1
  7. package/dist/Auth/AuthTypes.js.map +1 -1
  8. package/dist/Auth/endpoints/setCatchAllRequestHandler.d.ts.map +1 -1
  9. package/dist/Auth/endpoints/setCatchAllRequestHandler.js +26 -19
  10. package/dist/Auth/endpoints/setCatchAllRequestHandler.js.map +1 -1
  11. package/dist/Auth/getClientAuth.d.ts +1 -1
  12. package/dist/Auth/getClientAuth.d.ts.map +1 -1
  13. package/dist/Auth/getClientAuth.js +12 -4
  14. package/dist/Auth/getClientAuth.js.map +1 -1
  15. package/dist/Auth/login.d.ts +2 -1
  16. package/dist/Auth/login.d.ts.map +1 -1
  17. package/dist/Auth/login.js +20 -13
  18. package/dist/Auth/login.js.map +1 -1
  19. package/dist/Auth/setupAuthRoutes.d.ts.map +1 -1
  20. package/dist/Auth/setupAuthRoutes.js +11 -3
  21. package/dist/Auth/setupAuthRoutes.js.map +1 -1
  22. package/dist/Auth/utils/getSidAndUserFromRequest.d.ts +4 -2
  23. package/dist/Auth/utils/getSidAndUserFromRequest.d.ts.map +1 -1
  24. package/dist/Auth/utils/getSidAndUserFromRequest.js +40 -25
  25. package/dist/Auth/utils/getSidAndUserFromRequest.js.map +1 -1
  26. package/dist/Auth/utils/getUserOrError.d.ts +10 -0
  27. package/dist/Auth/utils/getUserOrError.d.ts.map +1 -0
  28. package/dist/Auth/utils/getUserOrError.js +48 -0
  29. package/dist/Auth/utils/getUserOrError.js.map +1 -0
  30. package/dist/Auth/utils/handleGetUser.d.ts +7 -0
  31. package/dist/Auth/utils/handleGetUser.d.ts.map +1 -0
  32. package/dist/Auth/utils/handleGetUser.js +47 -0
  33. package/dist/Auth/utils/handleGetUser.js.map +1 -0
  34. package/dist/DboBuilder/DboBuilderTypes.d.ts +2 -1
  35. package/dist/DboBuilder/DboBuilderTypes.d.ts.map +1 -1
  36. package/dist/Prostgles.d.ts.map +1 -1
  37. package/dist/Prostgles.js +6 -0
  38. package/dist/Prostgles.js.map +1 -1
  39. package/dist/PublishParser/PublishParser.d.ts +2 -2
  40. package/dist/PublishParser/PublishParser.d.ts.map +1 -1
  41. package/dist/PublishParser/PublishParser.js +11 -5
  42. package/dist/PublishParser/PublishParser.js.map +1 -1
  43. package/dist/PublishParser/getSchemaFromPublish.d.ts.map +1 -1
  44. package/dist/PublishParser/getSchemaFromPublish.js +70 -69
  45. package/dist/PublishParser/getSchemaFromPublish.js.map +1 -1
  46. package/dist/onSocketConnected.d.ts.map +1 -1
  47. package/dist/onSocketConnected.js +15 -14
  48. package/dist/onSocketConnected.js.map +1 -1
  49. package/dist/runClientRequest.d.ts.map +1 -1
  50. package/dist/runClientRequest.js +3 -0
  51. package/dist/runClientRequest.js.map +1 -1
  52. package/lib/Auth/AuthHandler.ts +42 -83
  53. package/lib/Auth/AuthTypes.ts +13 -3
  54. package/lib/Auth/endpoints/setCatchAllRequestHandler.ts +29 -24
  55. package/lib/Auth/getClientAuth.ts +28 -14
  56. package/lib/Auth/login.ts +24 -17
  57. package/lib/Auth/setupAuthRoutes.ts +12 -3
  58. package/lib/Auth/utils/getSidAndUserFromRequest.ts +42 -33
  59. package/lib/Auth/utils/getUserOrError.ts +56 -0
  60. package/lib/Auth/utils/handleGetUser.ts +63 -0
  61. package/lib/DboBuilder/DboBuilderTypes.ts +2 -1
  62. package/lib/Prostgles.ts +7 -0
  63. package/lib/PublishParser/PublishParser.ts +14 -6
  64. package/lib/PublishParser/getSchemaFromPublish.ts +97 -94
  65. package/lib/onSocketConnected.ts +15 -12
  66. package/lib/runClientRequest.ts +3 -0
  67. package/package.json +2 -2
@@ -5,25 +5,43 @@ import {
5
5
  CHANNELS,
6
6
  getObjectEntries,
7
7
  isEmpty,
8
+ isObject,
8
9
  } from "prostgles-types";
9
- import { AuthClientRequest, LoginWithOAuthConfig, AuthResultWithSID } from "./AuthTypes";
10
+ import {
11
+ AuthClientRequest,
12
+ LoginWithOAuthConfig,
13
+ AuthResultWithSID,
14
+ type AuthResult,
15
+ } from "./AuthTypes";
10
16
  import { AUTH_ROUTES_AND_PARAMS, AuthHandler } from "./AuthHandler";
11
17
 
12
18
  export async function getClientAuth(
13
19
  this: AuthHandler,
14
20
  clientReq: AuthClientRequest
15
- ): Promise<{ auth: AuthSocketSchema; userData: AuthResultWithSID }> {
21
+ ): Promise<{ auth: AuthSocketSchema; userData: AuthResultWithSID } | "new-session-redirect"> {
16
22
  let pathGuard = false;
17
- if (
18
- this.opts.loginSignupConfig?.publicRoutes &&
19
- !this.opts.loginSignupConfig.disableSocketAuthGuard
20
- ) {
23
+ const {
24
+ loginWithOAuth,
25
+ signupWithEmail: signupWithEmailAndPassword,
26
+ localLoginMode,
27
+ login,
28
+ publicRoutes,
29
+ disableSocketAuthGuard,
30
+ } = this.opts.loginSignupConfig ?? {};
31
+
32
+ if (publicRoutes && !disableSocketAuthGuard) {
21
33
  pathGuard = true;
22
34
 
23
35
  /**
24
36
  * Due to SPA nature of some clients, we need to check if the connected client ends up on a protected route
25
37
  */
26
38
  if (clientReq.socket) {
39
+ const getUserFromRequest = async (clientReq: AuthClientRequest): Promise<AuthResult> => {
40
+ const sidAndUser = await this.getSidAndUserFromRequest(clientReq);
41
+ if (isObject(sidAndUser) && sidAndUser.sid && sidAndUser.user) {
42
+ return sidAndUser;
43
+ }
44
+ };
27
45
  const { socket } = clientReq;
28
46
  socket.removeAllListeners(CHANNELS.AUTHGUARD);
29
47
  socket.on(
@@ -48,7 +66,7 @@ export async function getClientAuth(
48
66
  pathname &&
49
67
  typeof pathname === "string" &&
50
68
  this.isUserRoute(pathname) &&
51
- !(await this.getUserFromRequest({ socket }))
69
+ !(await getUserFromRequest({ socket }))
52
70
  ) {
53
71
  cb(null, { shouldReload: true });
54
72
  } else {
@@ -64,13 +82,9 @@ export async function getClientAuth(
64
82
  }
65
83
 
66
84
  const userData = await this.getSidAndUserFromRequest(clientReq);
67
- const {
68
- loginWithOAuth,
69
- signupWithEmail: signupWithEmailAndPassword,
70
- localLoginMode,
71
- login,
72
- } = this.opts.loginSignupConfig ?? {};
73
-
85
+ if (userData === "new-session-redirect") {
86
+ return userData;
87
+ }
74
88
  const auth: AuthSocketSchema = {
75
89
  providers: getOAuthProviders(loginWithOAuth),
76
90
  signupWithEmailAndPassword: signupWithEmailAndPassword && {
package/lib/Auth/login.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { DBOFullyTyped } from "../DBSchemaBuilder";
2
2
  import { AuthHandler, getClientRequestIPsInfo, HTTP_FAIL_CODES } from "./AuthHandler";
3
- import { ExpressReq, LoginParams } from "./AuthTypes";
3
+ import { ExpressReq, LoginParams, type BasicSession } from "./AuthTypes";
4
4
  import { LoginResponseHandler } from "./endpoints/setLoginRequestHandler";
5
5
  import { throttledAuthCall } from "./utils/throttledReject";
6
6
 
@@ -30,22 +30,9 @@ export async function login(
30
30
  return result;
31
31
  }
32
32
 
33
- const { sid, expires } = result.session;
34
- if (!sid) {
35
- console.error("Invalid sid");
36
- return "server-error";
37
- }
38
- if (sid && (typeof sid !== "string" || typeof expires !== "number")) {
39
- console.error(
40
- "Bad login result type. \nExpecting: undefined | null | { sid: string; expires: number }"
41
- );
42
- return "server-error";
43
- }
44
- if (expires < Date.now()) {
45
- console.error(
46
- "auth.login() is returning an expired session. Can only login with a session.expires greater than Date.now()"
47
- );
48
- return "server-error";
33
+ const sessionErrorCode = getBasicSessionErrorCode(result.session);
34
+ if (sessionErrorCode) {
35
+ return sessionErrorCode;
49
36
  }
50
37
 
51
38
  return result;
@@ -76,3 +63,23 @@ export async function login(
76
63
  }
77
64
  this.setCookieAndGoToReturnURLIFSet(loginResponse.session, { req, res });
78
65
  }
66
+
67
+ export const getBasicSessionErrorCode = (session: Pick<BasicSession, "expires" | "sid">) => {
68
+ const { sid, expires } = session;
69
+ if (!sid) {
70
+ console.error("Invalid sid");
71
+ return "server-error";
72
+ }
73
+ if (sid && (typeof sid !== "string" || typeof expires !== "number")) {
74
+ console.error(
75
+ "Bad login result type. \nExpecting: undefined | null | { sid: string; expires: number }"
76
+ );
77
+ return "server-error";
78
+ }
79
+ if (expires < Date.now()) {
80
+ console.error(
81
+ "auth.login() is returning an expired session. Can only login with a session.expires greater than Date.now()"
82
+ );
83
+ return "server-error";
84
+ }
85
+ };
@@ -42,17 +42,23 @@ export function setupAuthRoutes(this: AuthHandler) {
42
42
  if (onUseOrSocketConnected) {
43
43
  const prostglesUseMiddleware: RequestHandler = async (req, res, next) => {
44
44
  const reqInfo = { httpReq: req, res };
45
- const errorInfo = await onUseOrSocketConnected(
45
+ const errorInfoOrSession = await onUseOrSocketConnected(
46
46
  this.getSIDNoError(reqInfo),
47
47
  getClientRequestIPsInfo(reqInfo),
48
48
  reqInfo
49
49
  );
50
50
 
51
- if (errorInfo) {
52
- const { error, httpCode } = errorInfo;
51
+ if (errorInfoOrSession && "error" in errorInfoOrSession) {
52
+ const { error, httpCode } = errorInfoOrSession;
53
53
  res.status(httpCode).json({ error });
54
54
  return;
55
55
  }
56
+
57
+ if (errorInfoOrSession && "session" in errorInfoOrSession) {
58
+ const { session } = errorInfoOrSession;
59
+ this.validateSessionAndSetCookie(session, { req, res });
60
+ return;
61
+ }
56
62
  next();
57
63
  };
58
64
  upsertNamedExpressMiddleware(app, prostglesUseMiddleware, "prostglesonUseOrSocketConnected");
@@ -66,6 +72,9 @@ export function setupAuthRoutes(this: AuthHandler) {
66
72
  next,
67
73
  getUser: async () => {
68
74
  const userOrErr = await this.getUserOrError({ httpReq: req, res });
75
+ if (userOrErr === "new-session-redirect") {
76
+ throw "new-session-redirect";
77
+ }
69
78
  if (userOrErr.error) {
70
79
  res.status(HTTP_FAIL_CODES.BAD_REQUEST).json(userOrErr.error);
71
80
  throw userOrErr.error;
@@ -1,22 +1,25 @@
1
+ import { isObject } from "prostgles-types";
1
2
  import { DBOFullyTyped } from "../../DBSchemaBuilder";
2
3
  import { AuthHandler, getClientRequestIPsInfo } from "../AuthHandler";
3
4
  import { AuthClientRequest, AuthResultWithSID } from "../AuthTypes";
4
5
  import { throttledAuthCall } from "./throttledReject";
6
+ import type { GetUserOrRedirected } from "./handleGetUser";
5
7
 
6
8
  /**
7
9
  * For a given sid return the user data if available using the auth handler's getUser method.
8
10
  * Use socket session cache if configured in Auth
11
+ * Used in Publish Parser and AuthHandler
9
12
  */
10
13
  export async function getSidAndUserFromRequest(
11
14
  this: AuthHandler,
12
15
  clientReq: AuthClientRequest
13
- ): Promise<AuthResultWithSID> {
16
+ ): Promise<GetUserOrRedirected> {
14
17
  /**
15
18
  * Get cached session if available
16
19
  */
17
20
  const getSessionForCaching = this.opts.cacheSession?.getSession;
18
21
  if (clientReq.socket && getSessionForCaching && clientReq.socket.__prglCache) {
19
- const { session, ...userData } = clientReq.socket.__prglCache;
22
+ const { session, userData } = clientReq.socket.__prglCache;
20
23
  const isValid = this.isNonExpiredSocketSession(clientReq.socket, session);
21
24
  if (isValid) {
22
25
  return {
@@ -33,45 +36,51 @@ export async function getSidAndUserFromRequest(
33
36
  * Get sid from request and fetch user data
34
37
  */
35
38
  const authStart = Date.now();
36
- const result = await throttledAuthCall(async () => {
37
- const { getUser } = this.opts;
39
+ // const result = await throttledAuthCall(async () => {
40
+ // const clientInfoOrErr = await this.opts.getUser(
41
+ // this.getValidatedSid(clientReq),
42
+ // this.dbo as DBOFullyTyped,
43
+ // this.db,
44
+ // getClientRequestIPsInfo(clientReq),
45
+ // clientReq
46
+ // );
47
+ // if (clientInfoOrErr && (typeof clientInfoOrErr === "string" || "success" in clientInfoOrErr))
48
+ // throw clientInfoOrErr;
49
+ // const clientInfo = clientInfoOrErr;
38
50
 
39
- const sid = this.getSID(clientReq);
40
- const clientInfoOrErr =
41
- !sid ? undefined : (
42
- await getUser(
43
- sid,
44
- this.dbo as DBOFullyTyped,
45
- this.db,
46
- getClientRequestIPsInfo(clientReq),
47
- clientReq
48
- )
49
- );
50
- if (clientInfoOrErr && (typeof clientInfoOrErr === "string" || "success" in clientInfoOrErr))
51
- throw clientInfoOrErr;
52
- const clientInfo = clientInfoOrErr;
53
- if (getSessionForCaching && clientReq.socket && sid) {
54
- const session = await getSessionForCaching(sid, this.dbo as DBOFullyTyped, this.db);
55
- if (session && session.expires && clientInfo?.user) {
56
- clientReq.socket.__prglCache = {
57
- ...clientInfo,
58
- session,
59
- };
60
- }
61
- }
51
+ // if (clientInfo && "type" in clientInfo) {
52
+ // if (!("httpReq" in clientReq) || !clientReq.httpReq) throw "httpReq missing";
53
+ // const { httpReq, res } = clientReq;
54
+ // this.setCookieAndGoToReturnURLIFSet(clientInfo.session, { req: httpReq, res });
55
+ // return;
56
+ // }
62
57
 
63
- if (clientInfo?.user && sid) {
64
- return { sid, ...clientInfo };
65
- }
58
+ // const sid = this.getValidatedSid(clientReq);
59
+ // if (getSessionForCaching && clientReq.socket && sid) {
60
+ // const session = await getSessionForCaching(sid, this.dbo as DBOFullyTyped, this.db);
61
+ // if (session && session.expires && clientInfo?.user) {
62
+ // clientReq.socket.__prglCache = {
63
+ // userData: clientInfo,
64
+ // session,
65
+ // };
66
+ // }
67
+ // }
66
68
 
67
- return { sid, preferredLogin: !clientInfo?.user ? clientInfo?.preferredLogin : undefined };
68
- }, 100);
69
+ // if (clientInfo?.user && sid) {
70
+ // return { sid, ...clientInfo };
71
+ // }
69
72
 
73
+ // return { sid, preferredLogin: !clientInfo?.user ? clientInfo?.preferredLogin : undefined };
74
+ // }, 100);
75
+ const result = await this.handleGetUser(clientReq);
76
+ if (isObject(result) && result.error) {
77
+ throw result.error;
78
+ }
70
79
  await this.prostgles.opts.onLog?.({
71
80
  type: "auth",
72
81
  command: "getClientInfo",
73
82
  duration: Date.now() - authStart,
74
- sid: result.sid,
83
+ sid: isObject(result) ? result.sid : undefined,
75
84
  socketId: clientReq.socket?.id,
76
85
  });
77
86
  return result;
@@ -0,0 +1,56 @@
1
+ import { AuthResponse } from "prostgles-types";
2
+ import { DBOFullyTyped } from "../../DBSchemaBuilder";
3
+ import type { AuthHandler } from "../AuthHandler";
4
+ import { AuthClientRequest, AuthResultWithSID } from "../AuthTypes";
5
+ import { getClientRequestIPsInfo } from "../utils/getClientRequestIPsInfo";
6
+ import { isAuthError, type GetUserOrRedirected } from "./handleGetUser";
7
+ import { throttledAuthCall } from "./throttledReject";
8
+
9
+ /**
10
+ * Used by:
11
+ * - setCatchAllRequestHandler
12
+ * - loginSignupConfig.use
13
+ */
14
+ export async function getUserOrError(
15
+ this: AuthHandler,
16
+ clientReq: AuthClientRequest
17
+ ): Promise<GetUserOrRedirected> {
18
+ // const sid = this.getValidatedSid(clientReq);
19
+ // if (!sid) return { sid };
20
+
21
+ try {
22
+ // const userOrErrorCode = await throttledAuthCall(async () => {
23
+ // return this.opts.getUser(
24
+ // this.validateSid(sid),
25
+ // this.dbo as DBOFullyTyped,
26
+ // this.db,
27
+ // getClientRequestIPsInfo(clientReq),
28
+ // clientReq
29
+ // );
30
+ // }, 50);
31
+
32
+ // if (isAuthError(userOrErrorCode)) {
33
+ // const error: AuthResponse.AuthFailure | undefined =
34
+ // typeof userOrErrorCode === "string" ?
35
+ // { success: false, code: userOrErrorCode }
36
+ // : userOrErrorCode;
37
+
38
+ // return {
39
+ // sid,
40
+ // error,
41
+ // };
42
+ // }
43
+ // if (sid && userOrErrorCode?.user) {
44
+ // return { sid, ...userOrErrorCode };
45
+ // }
46
+ // return {
47
+ // sid,
48
+ // };
49
+ return this.handleGetUser(clientReq);
50
+ } catch (_err) {
51
+ return {
52
+ sid: this.getValidatedSid(clientReq),
53
+ error: { success: false, code: "server-error" },
54
+ };
55
+ }
56
+ }
@@ -0,0 +1,63 @@
1
+ import { AuthResponse, isObject } from "prostgles-types";
2
+ import type { DBOFullyTyped } from "../../DBSchemaBuilder";
3
+ import { getClientRequestIPsInfo, type AuthHandler } from "../AuthHandler";
4
+ import type { AuthClientRequest, AuthResultOrError, AuthResultWithSID } from "../AuthTypes";
5
+ import { throttledAuthCall } from "./throttledReject";
6
+
7
+ export type GetUserOrRedirected = AuthResultWithSID | "new-session-redirect";
8
+
9
+ export async function handleGetUserThrottled(
10
+ this: AuthHandler,
11
+ clientReq: AuthClientRequest
12
+ ): Promise<GetUserOrRedirected> {
13
+ const getSessionForCaching = this.opts.cacheSession?.getSession;
14
+ const result = await throttledAuthCall(async () => {
15
+ const clientInfoOrErr = await this.opts.getUser(
16
+ this.getValidatedSid(clientReq),
17
+ this.dbo as DBOFullyTyped,
18
+ this.db,
19
+ getClientRequestIPsInfo(clientReq),
20
+ clientReq
21
+ );
22
+ if (isAuthError(clientInfoOrErr)) {
23
+ return {
24
+ error:
25
+ isObject(clientInfoOrErr) ? clientInfoOrErr : { success: false, code: clientInfoOrErr },
26
+ sid: this.getValidatedSid(clientReq),
27
+ } satisfies AuthResultWithSID;
28
+ }
29
+ const clientInfo = clientInfoOrErr;
30
+
31
+ if (clientInfo && "type" in clientInfo) {
32
+ if (!("httpReq" in clientReq) || !clientReq.httpReq)
33
+ throw "httpReq missing. new-session not implemented for sockets.";
34
+ const { httpReq, res } = clientReq;
35
+ this.validateSessionAndSetCookie(clientInfo.session, { req: httpReq, res });
36
+ return "new-session-redirect" as const;
37
+ }
38
+
39
+ const sid = this.getValidatedSid(clientReq);
40
+ if (getSessionForCaching && clientReq.socket && sid) {
41
+ const session = await getSessionForCaching(sid, this.dbo as DBOFullyTyped, this.db);
42
+ if (session && session.expires && clientInfo?.user) {
43
+ clientReq.socket.__prglCache = {
44
+ userData: clientInfo,
45
+ session,
46
+ };
47
+ }
48
+ }
49
+
50
+ if (clientInfo?.user && sid) {
51
+ return { sid, ...clientInfo };
52
+ }
53
+
54
+ return { sid, preferredLogin: !clientInfo?.user ? clientInfo?.preferredLogin : undefined };
55
+ }, 100);
56
+ return result;
57
+ }
58
+
59
+ export const isAuthError = (
60
+ dataOrError: AuthResultOrError
61
+ ): dataOrError is AuthResponse.AuthFailure["code"] | AuthResponse.AuthFailure => {
62
+ return Boolean(typeof dataOrError === "string" || (dataOrError && "success" in dataOrError));
63
+ };
@@ -168,7 +168,8 @@ export type PRGLIOSocket = {
168
168
  };
169
169
 
170
170
  /** Used for session caching */
171
- __prglCache?: SessionUser & {
171
+ __prglCache?: {
172
+ userData: Omit<SessionUser, "session">;
172
173
  session: BasicSession;
173
174
  };
174
175
 
package/lib/Prostgles.ts CHANGED
@@ -32,6 +32,7 @@ import {
32
32
  CHANNELS,
33
33
  ClientSchema,
34
34
  SQLRequest,
35
+ includes,
35
36
  isObject,
36
37
  omitKeys,
37
38
  tryCatchV2,
@@ -366,6 +367,9 @@ export class Prostgles {
366
367
  : { type: "http" as const, ...clientReq };
367
368
 
368
369
  const userData = await this.authHandler?.getSidAndUserFromRequest(clientInfo);
370
+ if (userData === "new-session-redirect") {
371
+ throw "new-session-redirect";
372
+ }
369
373
  const { publishParser } = this;
370
374
  let fullSchema: Awaited<ReturnType<PublishParser["getSchemaFromPublish"]>> | undefined;
371
375
  let publishValidationError;
@@ -426,6 +430,9 @@ export class Prostgles {
426
430
  });
427
431
 
428
432
  const authInfo = await this.authHandler?.getClientAuth(clientReq);
433
+ if (authInfo === "new-session-redirect") {
434
+ throw "new-session-redirect";
435
+ }
429
436
 
430
437
  const clientSchema: ClientSchema = {
431
438
  schema,
@@ -10,12 +10,11 @@ import { getTableRulesWithoutFileTable } from "./getTableRulesWithoutFileTable";
10
10
  import {
11
11
  DboTable,
12
12
  DboTableCommand,
13
- ParsedPublishTable,
13
+ ParsedTableRule,
14
14
  PublishMethods,
15
15
  type PublishObject,
16
16
  PublishParams,
17
17
  RULE_TO_METHODS,
18
- ParsedTableRule,
19
18
  parsePublishTableRule,
20
19
  } from "./publishTypesAndUtils";
21
20
 
@@ -43,9 +42,14 @@ export class PublishParser {
43
42
  clientReq: AuthClientRequest,
44
43
  clientInfo: AuthResultWithSID | undefined
45
44
  ): Promise<PublishParams> {
45
+ const _clientInfo =
46
+ clientInfo ?? (await this.prostgles.authHandler?.getSidAndUserFromRequest(clientReq));
47
+ if (_clientInfo === "new-session-redirect") {
48
+ throw "new-session-redirect";
49
+ }
46
50
  return {
47
51
  sid: undefined,
48
- ...(clientInfo ?? (await this.prostgles.authHandler?.getSidAndUserFromRequest(clientReq))),
52
+ ..._clientInfo,
49
53
  dbo: this.dbo as DBOFullyTyped,
50
54
  db: this.db,
51
55
  clientReq,
@@ -109,6 +113,9 @@ export class PublishParser {
109
113
  }: DboTableCommand): Promise<ParsedTableRule> {
110
114
  const clientInfo =
111
115
  clientReq && (await this.prostgles.authHandler?.getSidAndUserFromRequest(clientReq));
116
+ if (clientInfo === "new-session-redirect") {
117
+ throw "new-session-redirect";
118
+ }
112
119
  const rules = await this.getValidatedRequestRule({ tableName, command, clientReq }, clientInfo);
113
120
  return rules;
114
121
  }
@@ -159,13 +166,14 @@ export class PublishParser {
159
166
  }
160
167
  }
161
168
 
162
- if (tableRule[rtm.rule]) {
163
- return tableRule;
164
- } else
169
+ if (!tableRule[rtm.rule]) {
165
170
  throw {
166
171
  stack: ["getValidatedRequestRule()"],
167
172
  message: `Invalid or disallowed command: ${tableName}.${command}`,
168
173
  };
174
+ }
175
+
176
+ return tableRule;
169
177
  }
170
178
 
171
179
  async getTableRules(