naystack 1.8.2 → 1.8.4
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/dist/auth/client.cjs.js +51 -8
- package/dist/auth/client.d.mts +1 -0
- package/dist/auth/client.d.ts +1 -0
- package/dist/auth/client.esm.js +48 -8
- package/dist/auth/email/client.cjs.js +51 -8
- package/dist/auth/email/client.d.mts +1 -0
- package/dist/auth/email/client.d.ts +1 -0
- package/dist/auth/email/client.esm.js +48 -8
- package/dist/auth/email/index.cjs.js +4 -2
- package/dist/auth/email/index.d.mts +1 -0
- package/dist/auth/email/index.d.ts +1 -0
- package/dist/auth/email/index.esm.js +4 -2
- package/dist/auth/email/next.d.mts +1 -0
- package/dist/auth/email/next.d.ts +1 -0
- package/dist/auth/email/routes/delete.cjs.js +4 -2
- package/dist/auth/email/routes/delete.esm.js +4 -2
- package/dist/auth/email/routes/get.cjs.js +4 -2
- package/dist/auth/email/routes/get.esm.js +4 -2
- package/dist/auth/email/routes/post.cjs.js +4 -2
- package/dist/auth/email/routes/post.esm.js +4 -2
- package/dist/auth/email/routes/put.cjs.js +4 -2
- package/dist/auth/email/routes/put.esm.js +4 -2
- package/dist/auth/email/token.cjs.js +4 -2
- package/dist/auth/email/token.d.mts +2 -2
- package/dist/auth/email/token.d.ts +2 -2
- package/dist/auth/email/token.esm.js +4 -2
- package/dist/auth/google/get.cjs.js +3 -1
- package/dist/auth/google/get.esm.js +3 -1
- package/dist/auth/google/index.cjs.js +3 -1
- package/dist/auth/google/index.esm.js +3 -1
- package/dist/auth/index.cjs.js +4 -2
- package/dist/auth/index.d.mts +1 -0
- package/dist/auth/index.d.ts +1 -0
- package/dist/auth/index.esm.js +4 -2
- package/dist/auth/token-store.cjs.js +120 -0
- package/dist/auth/token-store.d.mts +42 -0
- package/dist/auth/token-store.d.ts +42 -0
- package/dist/auth/token-store.esm.js +90 -0
- package/dist/graphql/clear-store.cjs.js +47 -0
- package/dist/graphql/clear-store.d.mts +16 -0
- package/dist/graphql/clear-store.d.ts +16 -0
- package/dist/graphql/clear-store.esm.js +23 -0
- package/dist/graphql/client.cjs.js +116 -21
- package/dist/graphql/client.d.mts +4 -4
- package/dist/graphql/client.d.ts +4 -4
- package/dist/graphql/client.esm.js +113 -19
- package/dist/graphql/links.cjs.js +154 -0
- package/dist/graphql/links.d.mts +14 -0
- package/dist/graphql/links.d.ts +14 -0
- package/dist/graphql/links.esm.js +129 -0
- package/dist/graphql/next.cjs.js +99 -6
- package/dist/graphql/next.esm.js +98 -5
- package/package.json +1 -1
|
@@ -65,7 +65,9 @@ var REFRESH_COOKIE_NAME = "refresh";
|
|
|
65
65
|
|
|
66
66
|
// src/auth/email/token.ts
|
|
67
67
|
function generateRefreshToken(id) {
|
|
68
|
-
return sign({ id }, getEnv("REFRESH_KEY" /* REFRESH_KEY */)
|
|
68
|
+
return sign({ id }, getEnv("REFRESH_KEY" /* REFRESH_KEY */), {
|
|
69
|
+
expiresIn: "365d"
|
|
70
|
+
});
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
// src/auth/google/get.ts
|
|
@@ -91,7 +91,9 @@ var REFRESH_COOKIE_NAME = "refresh";
|
|
|
91
91
|
|
|
92
92
|
// src/auth/email/token.ts
|
|
93
93
|
function generateRefreshToken(id) {
|
|
94
|
-
return (0, import_jsonwebtoken.sign)({ id }, getEnv("REFRESH_KEY" /* REFRESH_KEY */)
|
|
94
|
+
return (0, import_jsonwebtoken.sign)({ id }, getEnv("REFRESH_KEY" /* REFRESH_KEY */), {
|
|
95
|
+
expiresIn: "365d"
|
|
96
|
+
});
|
|
95
97
|
}
|
|
96
98
|
|
|
97
99
|
// src/auth/google/get.ts
|
|
@@ -65,7 +65,9 @@ var REFRESH_COOKIE_NAME = "refresh";
|
|
|
65
65
|
|
|
66
66
|
// src/auth/email/token.ts
|
|
67
67
|
function generateRefreshToken(id) {
|
|
68
|
-
return sign({ id }, getEnv("REFRESH_KEY" /* REFRESH_KEY */)
|
|
68
|
+
return sign({ id }, getEnv("REFRESH_KEY" /* REFRESH_KEY */), {
|
|
69
|
+
expiresIn: "365d"
|
|
70
|
+
});
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
// src/auth/google/get.ts
|
package/dist/auth/index.cjs.js
CHANGED
|
@@ -150,11 +150,13 @@ function getEnv(key, skipCheck) {
|
|
|
150
150
|
// src/auth/email/token.ts
|
|
151
151
|
function generateAccessToken(id) {
|
|
152
152
|
return (0, import_jsonwebtoken.sign)({ id }, getEnv("SIGNING_KEY" /* SIGNING_KEY */), {
|
|
153
|
-
expiresIn: "
|
|
153
|
+
expiresIn: "24h"
|
|
154
154
|
});
|
|
155
155
|
}
|
|
156
156
|
function generateRefreshToken(id) {
|
|
157
|
-
return (0, import_jsonwebtoken.sign)({ id }, getEnv("REFRESH_KEY" /* REFRESH_KEY */)
|
|
157
|
+
return (0, import_jsonwebtoken.sign)({ id }, getEnv("REFRESH_KEY" /* REFRESH_KEY */), {
|
|
158
|
+
expiresIn: "365d"
|
|
159
|
+
});
|
|
158
160
|
}
|
|
159
161
|
function getTokenizedResponse(id) {
|
|
160
162
|
const accessToken = id ? generateAccessToken(id) : void 0;
|
package/dist/auth/index.d.mts
CHANGED
package/dist/auth/index.d.ts
CHANGED
package/dist/auth/index.esm.js
CHANGED
|
@@ -104,11 +104,13 @@ function getEnv(key, skipCheck) {
|
|
|
104
104
|
// src/auth/email/token.ts
|
|
105
105
|
function generateAccessToken(id) {
|
|
106
106
|
return sign({ id }, getEnv("SIGNING_KEY" /* SIGNING_KEY */), {
|
|
107
|
-
expiresIn: "
|
|
107
|
+
expiresIn: "24h"
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
110
|
function generateRefreshToken(id) {
|
|
111
|
-
return sign({ id }, getEnv("REFRESH_KEY" /* REFRESH_KEY */)
|
|
111
|
+
return sign({ id }, getEnv("REFRESH_KEY" /* REFRESH_KEY */), {
|
|
112
|
+
expiresIn: "365d"
|
|
113
|
+
});
|
|
112
114
|
}
|
|
113
115
|
function getTokenizedResponse(id) {
|
|
114
116
|
const accessToken = id ? generateAccessToken(id) : void 0;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/auth/token-store.ts
|
|
21
|
+
var token_store_exports = {};
|
|
22
|
+
__export(token_store_exports, {
|
|
23
|
+
getAccessToken: () => getAccessToken,
|
|
24
|
+
refreshAccessToken: () => refreshAccessToken,
|
|
25
|
+
setAccessToken: () => setAccessToken,
|
|
26
|
+
subscribeToAccessToken: () => subscribeToAccessToken
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(token_store_exports);
|
|
29
|
+
|
|
30
|
+
// src/env.ts
|
|
31
|
+
var EXTRA_ENV = globalThis.__NAYSTACK_ENV__ || (globalThis.__NAYSTACK_ENV__ = {});
|
|
32
|
+
var getEnvValue = (key) => {
|
|
33
|
+
switch (key) {
|
|
34
|
+
case "NEXT_PUBLIC_GRAPHQL_ENDPOINT" /* NEXT_PUBLIC_GRAPHQL_ENDPOINT */:
|
|
35
|
+
return process.env.NEXT_PUBLIC_GRAPHQL_ENDPOINT || EXTRA_ENV.GRAPHQL_ENDPOINT;
|
|
36
|
+
case "NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT" /* NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT */:
|
|
37
|
+
return process.env.NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT || EXTRA_ENV.EMAIL_AUTH_ENDPOINT;
|
|
38
|
+
case "NEXT_PUBLIC_GOOGLE_AUTH_ENDPOINT" /* NEXT_PUBLIC_GOOGLE_AUTH_ENDPOINT */:
|
|
39
|
+
return process.env.NEXT_PUBLIC_GOOGLE_AUTH_ENDPOINT || EXTRA_ENV.GOOGLE_AUTH_ENDPOINT;
|
|
40
|
+
case "NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT" /* NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT */:
|
|
41
|
+
return process.env.NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT || EXTRA_ENV.INSTAGRAM_AUTH_ENDPOINT;
|
|
42
|
+
case "NEXT_PUBLIC_FILE_ENDPOINT" /* NEXT_PUBLIC_FILE_ENDPOINT */:
|
|
43
|
+
return process.env.NEXT_PUBLIC_FILE_ENDPOINT || EXTRA_ENV.FILE_ENDPOINT;
|
|
44
|
+
case "NEXT_PUBLIC_BASE_URL" /* NEXT_PUBLIC_BASE_URL */:
|
|
45
|
+
return process.env.NEXT_PUBLIC_BASE_URL || EXTRA_ENV.BASE_URL;
|
|
46
|
+
case "REFRESH_KEY" /* REFRESH_KEY */:
|
|
47
|
+
return process.env.REFRESH_KEY;
|
|
48
|
+
case "SIGNING_KEY" /* SIGNING_KEY */:
|
|
49
|
+
return process.env.SIGNING_KEY;
|
|
50
|
+
case "INSTAGRAM_CLIENT_SECRET" /* INSTAGRAM_CLIENT_SECRET */:
|
|
51
|
+
return process.env.INSTAGRAM_CLIENT_SECRET;
|
|
52
|
+
case "INSTAGRAM_CLIENT_ID" /* INSTAGRAM_CLIENT_ID */:
|
|
53
|
+
return process.env.INSTAGRAM_CLIENT_ID;
|
|
54
|
+
case "GOOGLE_CLIENT_SECRET" /* GOOGLE_CLIENT_SECRET */:
|
|
55
|
+
return process.env.GOOGLE_CLIENT_SECRET;
|
|
56
|
+
case "GOOGLE_CLIENT_ID" /* GOOGLE_CLIENT_ID */:
|
|
57
|
+
return process.env.GOOGLE_CLIENT_ID;
|
|
58
|
+
case "TURNSTILE_KEY" /* TURNSTILE_KEY */:
|
|
59
|
+
return process.env.TURNSTILE_KEY;
|
|
60
|
+
case "S3_ACCESS_KEY_ID" /* S3_ACCESS_KEY_ID */:
|
|
61
|
+
return process.env.S3_ACCESS_KEY_ID;
|
|
62
|
+
case "S3_ACCESS_KEY_SECRET" /* S3_ACCESS_KEY_SECRET */:
|
|
63
|
+
return process.env.S3_ACCESS_KEY_SECRET;
|
|
64
|
+
case "S3_REGION" /* S3_REGION */:
|
|
65
|
+
return process.env.S3_REGION;
|
|
66
|
+
case "S3_BUCKET" /* S3_BUCKET */:
|
|
67
|
+
return process.env.S3_BUCKET;
|
|
68
|
+
case "NODE_ENV" /* NODE_ENV */:
|
|
69
|
+
return process.env.NODE_ENV;
|
|
70
|
+
default:
|
|
71
|
+
return process.env[key];
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
function getEnv(key, skipCheck) {
|
|
75
|
+
const value = getEnvValue(key);
|
|
76
|
+
if (!skipCheck && !value) throw new Error(`${key} is not defined`);
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// src/auth/token-store.ts
|
|
81
|
+
var currentToken;
|
|
82
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
83
|
+
var inFlightRefresh = null;
|
|
84
|
+
function getAccessToken() {
|
|
85
|
+
return currentToken;
|
|
86
|
+
}
|
|
87
|
+
function setAccessToken(token) {
|
|
88
|
+
if (token === currentToken) return;
|
|
89
|
+
currentToken = token;
|
|
90
|
+
listeners.forEach((listener) => listener(token));
|
|
91
|
+
}
|
|
92
|
+
function subscribeToAccessToken(listener) {
|
|
93
|
+
listeners.add(listener);
|
|
94
|
+
return () => {
|
|
95
|
+
listeners.delete(listener);
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function refreshAccessToken() {
|
|
99
|
+
if (inFlightRefresh) return inFlightRefresh;
|
|
100
|
+
inFlightRefresh = (async () => {
|
|
101
|
+
const res = await fetch(
|
|
102
|
+
getEnv("NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT" /* NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT */),
|
|
103
|
+
{ credentials: "include" }
|
|
104
|
+
);
|
|
105
|
+
if (!res.ok) throw new Error(`Token refresh failed: ${res.status}`);
|
|
106
|
+
const token = await res.text() || null;
|
|
107
|
+
setAccessToken(token);
|
|
108
|
+
return token;
|
|
109
|
+
})().finally(() => {
|
|
110
|
+
inFlightRefresh = null;
|
|
111
|
+
});
|
|
112
|
+
return inFlightRefresh;
|
|
113
|
+
}
|
|
114
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
115
|
+
0 && (module.exports = {
|
|
116
|
+
getAccessToken,
|
|
117
|
+
refreshAccessToken,
|
|
118
|
+
setAccessToken,
|
|
119
|
+
subscribeToAccessToken
|
|
120
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads the current access token synchronously, outside React.
|
|
3
|
+
* Used by the Apollo auth link; components should use `useToken()`.
|
|
4
|
+
*
|
|
5
|
+
* @returns The access token, `null` when logged out, or `undefined` before the first fetch resolves.
|
|
6
|
+
* @category Auth
|
|
7
|
+
*/
|
|
8
|
+
declare function getAccessToken(): string | null | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Writes the access token and notifies subscribers (which updates `TokenContext`).
|
|
11
|
+
*
|
|
12
|
+
* @param token - New token, or `null` to clear the session.
|
|
13
|
+
* @category Auth
|
|
14
|
+
*/
|
|
15
|
+
declare function setAccessToken(token: string | null | undefined): void;
|
|
16
|
+
/**
|
|
17
|
+
* Subscribes to token changes. `AuthWrapper` uses this to mirror the store into React state.
|
|
18
|
+
*
|
|
19
|
+
* @param listener - Called with the new token on every change.
|
|
20
|
+
* @returns Unsubscribe function.
|
|
21
|
+
* @category Auth
|
|
22
|
+
*/
|
|
23
|
+
declare function subscribeToAccessToken(listener: (token: string | null | undefined) => void): () => void;
|
|
24
|
+
/**
|
|
25
|
+
* Exchanges the httpOnly refresh cookie for a fresh access token via the auth endpoint,
|
|
26
|
+
* and stores the result. Concurrent callers share one request.
|
|
27
|
+
*
|
|
28
|
+
* The auth endpoint answers 200 in both directions, so the body is the signal:
|
|
29
|
+
* a token means the session is alive, an empty body means the refresh cookie is
|
|
30
|
+
* gone or expired and the user is logged out (which clears the token, and in turn
|
|
31
|
+
* trips `ClearStoreOnLogout`).
|
|
32
|
+
*
|
|
33
|
+
* A transport failure (offline, 5xx) rejects **without** clearing the token — a
|
|
34
|
+
* flaky network shouldn't end a valid session.
|
|
35
|
+
*
|
|
36
|
+
* @returns The new access token, or `null` if the session has ended.
|
|
37
|
+
* @throws If the request fails at the transport level or the endpoint returns non-2xx.
|
|
38
|
+
* @category Auth
|
|
39
|
+
*/
|
|
40
|
+
declare function refreshAccessToken(): Promise<string | null>;
|
|
41
|
+
|
|
42
|
+
export { getAccessToken, refreshAccessToken, setAccessToken, subscribeToAccessToken };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads the current access token synchronously, outside React.
|
|
3
|
+
* Used by the Apollo auth link; components should use `useToken()`.
|
|
4
|
+
*
|
|
5
|
+
* @returns The access token, `null` when logged out, or `undefined` before the first fetch resolves.
|
|
6
|
+
* @category Auth
|
|
7
|
+
*/
|
|
8
|
+
declare function getAccessToken(): string | null | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Writes the access token and notifies subscribers (which updates `TokenContext`).
|
|
11
|
+
*
|
|
12
|
+
* @param token - New token, or `null` to clear the session.
|
|
13
|
+
* @category Auth
|
|
14
|
+
*/
|
|
15
|
+
declare function setAccessToken(token: string | null | undefined): void;
|
|
16
|
+
/**
|
|
17
|
+
* Subscribes to token changes. `AuthWrapper` uses this to mirror the store into React state.
|
|
18
|
+
*
|
|
19
|
+
* @param listener - Called with the new token on every change.
|
|
20
|
+
* @returns Unsubscribe function.
|
|
21
|
+
* @category Auth
|
|
22
|
+
*/
|
|
23
|
+
declare function subscribeToAccessToken(listener: (token: string | null | undefined) => void): () => void;
|
|
24
|
+
/**
|
|
25
|
+
* Exchanges the httpOnly refresh cookie for a fresh access token via the auth endpoint,
|
|
26
|
+
* and stores the result. Concurrent callers share one request.
|
|
27
|
+
*
|
|
28
|
+
* The auth endpoint answers 200 in both directions, so the body is the signal:
|
|
29
|
+
* a token means the session is alive, an empty body means the refresh cookie is
|
|
30
|
+
* gone or expired and the user is logged out (which clears the token, and in turn
|
|
31
|
+
* trips `ClearStoreOnLogout`).
|
|
32
|
+
*
|
|
33
|
+
* A transport failure (offline, 5xx) rejects **without** clearing the token — a
|
|
34
|
+
* flaky network shouldn't end a valid session.
|
|
35
|
+
*
|
|
36
|
+
* @returns The new access token, or `null` if the session has ended.
|
|
37
|
+
* @throws If the request fails at the transport level or the endpoint returns non-2xx.
|
|
38
|
+
* @category Auth
|
|
39
|
+
*/
|
|
40
|
+
declare function refreshAccessToken(): Promise<string | null>;
|
|
41
|
+
|
|
42
|
+
export { getAccessToken, refreshAccessToken, setAccessToken, subscribeToAccessToken };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// src/env.ts
|
|
2
|
+
var EXTRA_ENV = globalThis.__NAYSTACK_ENV__ || (globalThis.__NAYSTACK_ENV__ = {});
|
|
3
|
+
var getEnvValue = (key) => {
|
|
4
|
+
switch (key) {
|
|
5
|
+
case "NEXT_PUBLIC_GRAPHQL_ENDPOINT" /* NEXT_PUBLIC_GRAPHQL_ENDPOINT */:
|
|
6
|
+
return process.env.NEXT_PUBLIC_GRAPHQL_ENDPOINT || EXTRA_ENV.GRAPHQL_ENDPOINT;
|
|
7
|
+
case "NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT" /* NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT */:
|
|
8
|
+
return process.env.NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT || EXTRA_ENV.EMAIL_AUTH_ENDPOINT;
|
|
9
|
+
case "NEXT_PUBLIC_GOOGLE_AUTH_ENDPOINT" /* NEXT_PUBLIC_GOOGLE_AUTH_ENDPOINT */:
|
|
10
|
+
return process.env.NEXT_PUBLIC_GOOGLE_AUTH_ENDPOINT || EXTRA_ENV.GOOGLE_AUTH_ENDPOINT;
|
|
11
|
+
case "NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT" /* NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT */:
|
|
12
|
+
return process.env.NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT || EXTRA_ENV.INSTAGRAM_AUTH_ENDPOINT;
|
|
13
|
+
case "NEXT_PUBLIC_FILE_ENDPOINT" /* NEXT_PUBLIC_FILE_ENDPOINT */:
|
|
14
|
+
return process.env.NEXT_PUBLIC_FILE_ENDPOINT || EXTRA_ENV.FILE_ENDPOINT;
|
|
15
|
+
case "NEXT_PUBLIC_BASE_URL" /* NEXT_PUBLIC_BASE_URL */:
|
|
16
|
+
return process.env.NEXT_PUBLIC_BASE_URL || EXTRA_ENV.BASE_URL;
|
|
17
|
+
case "REFRESH_KEY" /* REFRESH_KEY */:
|
|
18
|
+
return process.env.REFRESH_KEY;
|
|
19
|
+
case "SIGNING_KEY" /* SIGNING_KEY */:
|
|
20
|
+
return process.env.SIGNING_KEY;
|
|
21
|
+
case "INSTAGRAM_CLIENT_SECRET" /* INSTAGRAM_CLIENT_SECRET */:
|
|
22
|
+
return process.env.INSTAGRAM_CLIENT_SECRET;
|
|
23
|
+
case "INSTAGRAM_CLIENT_ID" /* INSTAGRAM_CLIENT_ID */:
|
|
24
|
+
return process.env.INSTAGRAM_CLIENT_ID;
|
|
25
|
+
case "GOOGLE_CLIENT_SECRET" /* GOOGLE_CLIENT_SECRET */:
|
|
26
|
+
return process.env.GOOGLE_CLIENT_SECRET;
|
|
27
|
+
case "GOOGLE_CLIENT_ID" /* GOOGLE_CLIENT_ID */:
|
|
28
|
+
return process.env.GOOGLE_CLIENT_ID;
|
|
29
|
+
case "TURNSTILE_KEY" /* TURNSTILE_KEY */:
|
|
30
|
+
return process.env.TURNSTILE_KEY;
|
|
31
|
+
case "S3_ACCESS_KEY_ID" /* S3_ACCESS_KEY_ID */:
|
|
32
|
+
return process.env.S3_ACCESS_KEY_ID;
|
|
33
|
+
case "S3_ACCESS_KEY_SECRET" /* S3_ACCESS_KEY_SECRET */:
|
|
34
|
+
return process.env.S3_ACCESS_KEY_SECRET;
|
|
35
|
+
case "S3_REGION" /* S3_REGION */:
|
|
36
|
+
return process.env.S3_REGION;
|
|
37
|
+
case "S3_BUCKET" /* S3_BUCKET */:
|
|
38
|
+
return process.env.S3_BUCKET;
|
|
39
|
+
case "NODE_ENV" /* NODE_ENV */:
|
|
40
|
+
return process.env.NODE_ENV;
|
|
41
|
+
default:
|
|
42
|
+
return process.env[key];
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
function getEnv(key, skipCheck) {
|
|
46
|
+
const value = getEnvValue(key);
|
|
47
|
+
if (!skipCheck && !value) throw new Error(`${key} is not defined`);
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// src/auth/token-store.ts
|
|
52
|
+
var currentToken;
|
|
53
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
54
|
+
var inFlightRefresh = null;
|
|
55
|
+
function getAccessToken() {
|
|
56
|
+
return currentToken;
|
|
57
|
+
}
|
|
58
|
+
function setAccessToken(token) {
|
|
59
|
+
if (token === currentToken) return;
|
|
60
|
+
currentToken = token;
|
|
61
|
+
listeners.forEach((listener) => listener(token));
|
|
62
|
+
}
|
|
63
|
+
function subscribeToAccessToken(listener) {
|
|
64
|
+
listeners.add(listener);
|
|
65
|
+
return () => {
|
|
66
|
+
listeners.delete(listener);
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function refreshAccessToken() {
|
|
70
|
+
if (inFlightRefresh) return inFlightRefresh;
|
|
71
|
+
inFlightRefresh = (async () => {
|
|
72
|
+
const res = await fetch(
|
|
73
|
+
getEnv("NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT" /* NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT */),
|
|
74
|
+
{ credentials: "include" }
|
|
75
|
+
);
|
|
76
|
+
if (!res.ok) throw new Error(`Token refresh failed: ${res.status}`);
|
|
77
|
+
const token = await res.text() || null;
|
|
78
|
+
setAccessToken(token);
|
|
79
|
+
return token;
|
|
80
|
+
})().finally(() => {
|
|
81
|
+
inFlightRefresh = null;
|
|
82
|
+
});
|
|
83
|
+
return inFlightRefresh;
|
|
84
|
+
}
|
|
85
|
+
export {
|
|
86
|
+
getAccessToken,
|
|
87
|
+
refreshAccessToken,
|
|
88
|
+
setAccessToken,
|
|
89
|
+
subscribeToAccessToken
|
|
90
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/graphql/clear-store.tsx
|
|
22
|
+
var clear_store_exports = {};
|
|
23
|
+
__export(clear_store_exports, {
|
|
24
|
+
ClearStoreOnLogout: () => ClearStoreOnLogout
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(clear_store_exports);
|
|
27
|
+
var import_client = require("@apollo/client");
|
|
28
|
+
var import_client2 = require("naystack/auth/client");
|
|
29
|
+
var import_react = require("react");
|
|
30
|
+
function ClearStoreOnLogout() {
|
|
31
|
+
const client = (0, import_client.useApolloClient)();
|
|
32
|
+
const token = (0, import_client2.useToken)();
|
|
33
|
+
const hadToken = (0, import_react.useRef)(false);
|
|
34
|
+
(0, import_react.useEffect)(() => {
|
|
35
|
+
if (token) {
|
|
36
|
+
hadToken.current = true;
|
|
37
|
+
} else if (token === null && hadToken.current) {
|
|
38
|
+
hadToken.current = false;
|
|
39
|
+
void client.clearStore();
|
|
40
|
+
}
|
|
41
|
+
}, [client, token]);
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
ClearStoreOnLogout
|
|
47
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clears the Apollo cache on logout so a subsequent login can't read the
|
|
3
|
+
* previous user's cached data. Mount inside an `ApolloProvider` — both the
|
|
4
|
+
* native (`ApolloWrapper` in `graphql/client`) and Next (`graphql/next`)
|
|
5
|
+
* wrappers render it, so any query that opts into a cache-reading `fetchPolicy`
|
|
6
|
+
* is safe across account switches without per-call-site cleanup.
|
|
7
|
+
*
|
|
8
|
+
* Keyed on the token transitioning to `null` (logout / session loss). Same-user
|
|
9
|
+
* access-token refreshes go string→string and never pass through `null`, so the
|
|
10
|
+
* cache survives them; only a real logout empties the store. Renders nothing.
|
|
11
|
+
*
|
|
12
|
+
* @category GraphQL
|
|
13
|
+
*/
|
|
14
|
+
declare function ClearStoreOnLogout(): null;
|
|
15
|
+
|
|
16
|
+
export { ClearStoreOnLogout };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clears the Apollo cache on logout so a subsequent login can't read the
|
|
3
|
+
* previous user's cached data. Mount inside an `ApolloProvider` — both the
|
|
4
|
+
* native (`ApolloWrapper` in `graphql/client`) and Next (`graphql/next`)
|
|
5
|
+
* wrappers render it, so any query that opts into a cache-reading `fetchPolicy`
|
|
6
|
+
* is safe across account switches without per-call-site cleanup.
|
|
7
|
+
*
|
|
8
|
+
* Keyed on the token transitioning to `null` (logout / session loss). Same-user
|
|
9
|
+
* access-token refreshes go string→string and never pass through `null`, so the
|
|
10
|
+
* cache survives them; only a real logout empties the store. Renders nothing.
|
|
11
|
+
*
|
|
12
|
+
* @category GraphQL
|
|
13
|
+
*/
|
|
14
|
+
declare function ClearStoreOnLogout(): null;
|
|
15
|
+
|
|
16
|
+
export { ClearStoreOnLogout };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/graphql/clear-store.tsx
|
|
4
|
+
import { useApolloClient } from "@apollo/client";
|
|
5
|
+
import { useToken } from "naystack/auth/client";
|
|
6
|
+
import { useEffect, useRef } from "react";
|
|
7
|
+
function ClearStoreOnLogout() {
|
|
8
|
+
const client = useApolloClient();
|
|
9
|
+
const token = useToken();
|
|
10
|
+
const hadToken = useRef(false);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (token) {
|
|
13
|
+
hadToken.current = true;
|
|
14
|
+
} else if (token === null && hadToken.current) {
|
|
15
|
+
hadToken.current = false;
|
|
16
|
+
void client.clearStore();
|
|
17
|
+
}
|
|
18
|
+
}, [client, token]);
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
ClearStoreOnLogout
|
|
23
|
+
};
|