naystack 1.5.18 → 1.5.20
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/email/index.cjs.js +67 -0
- package/dist/auth/email/index.d.mts +2 -0
- package/dist/auth/email/index.d.ts +2 -0
- package/dist/auth/email/index.esm.js +60 -0
- package/dist/auth/email/server.cjs.js +9 -28
- package/dist/auth/email/server.esm.js +13 -38
- package/dist/auth/index.cjs.js +79 -12
- package/dist/auth/index.d.mts +2 -0
- package/dist/auth/index.d.ts +2 -0
- package/dist/auth/index.esm.js +62 -2
- package/package.json +1 -1
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,11 +17,20 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/auth/email/index.ts
|
|
21
31
|
var email_exports = {};
|
|
22
32
|
__export(email_exports, {
|
|
33
|
+
AuthFetch: () => AuthFetch,
|
|
23
34
|
checkAuthStatus: () => checkAuthStatus,
|
|
24
35
|
getContext: () => getContext,
|
|
25
36
|
getEmailAuthRoutes: () => getEmailAuthRoutes
|
|
@@ -298,6 +309,61 @@ var getPutRoute = (options) => async (req) => {
|
|
|
298
309
|
return handleError(403, "Invalid password", options.onError);
|
|
299
310
|
};
|
|
300
311
|
|
|
312
|
+
// src/auth/email/server.tsx
|
|
313
|
+
var import_client2 = require("naystack/auth/email/client");
|
|
314
|
+
var import_headers3 = require("next/headers");
|
|
315
|
+
|
|
316
|
+
// src/graphql/server.tsx
|
|
317
|
+
var import_client = require("@apollo/client");
|
|
318
|
+
var import_client_integration_nextjs = require("@apollo/client-integration-nextjs");
|
|
319
|
+
var import_headers2 = require("next/headers");
|
|
320
|
+
var import_react = __toESM(require("react"));
|
|
321
|
+
var import_react2 = require("react");
|
|
322
|
+
function Injector({
|
|
323
|
+
fetch: fetch2,
|
|
324
|
+
Component,
|
|
325
|
+
props
|
|
326
|
+
}) {
|
|
327
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react2.Suspense, { fallback: /* @__PURE__ */ import_react.default.createElement(Component, { ...props || {}, loading: true }) }, /* @__PURE__ */ import_react.default.createElement(InjectorSuspensed, { Component, fetch: fetch2, props }));
|
|
328
|
+
}
|
|
329
|
+
async function InjectorSuspensed({
|
|
330
|
+
fetch: fetch2,
|
|
331
|
+
Component,
|
|
332
|
+
props
|
|
333
|
+
}) {
|
|
334
|
+
const data = await fetch2();
|
|
335
|
+
return /* @__PURE__ */ import_react.default.createElement(Component, { loading: false, ...props || {}, data });
|
|
336
|
+
}
|
|
337
|
+
var { query: gqlQuery } = (0, import_client_integration_nextjs.registerApolloClient)(() => {
|
|
338
|
+
return new import_client.ApolloClient({
|
|
339
|
+
cache: new import_client.InMemoryCache(),
|
|
340
|
+
link: new import_client.HttpLink({
|
|
341
|
+
uri: getEnv("NEXT_PUBLIC_GRAPHQL_ENDPOINT" /* NEXT_PUBLIC_GRAPHQL_ENDPOINT */)
|
|
342
|
+
})
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
// src/auth/email/server.tsx
|
|
347
|
+
function AuthFetch() {
|
|
348
|
+
return /* @__PURE__ */ React.createElement(
|
|
349
|
+
Injector,
|
|
350
|
+
{
|
|
351
|
+
fetch: async () => {
|
|
352
|
+
const cookie = await (0, import_headers3.cookies)();
|
|
353
|
+
const token = cookie.get("refresh");
|
|
354
|
+
if (!token) return null;
|
|
355
|
+
return fetch(process.env.NEXT_PUBLIC_BACKEND_BASE_URL + `/email`, {
|
|
356
|
+
credentials: "include",
|
|
357
|
+
headers: {
|
|
358
|
+
Cookie: cookie.toString()
|
|
359
|
+
}
|
|
360
|
+
}).then((res) => res.json()).then((data) => data.accessToken).catch(() => null);
|
|
361
|
+
},
|
|
362
|
+
Component: import_client2.AuthApply
|
|
363
|
+
}
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
|
|
301
367
|
// src/auth/email/index.ts
|
|
302
368
|
function getEmailAuthRoutes(options) {
|
|
303
369
|
return {
|
|
@@ -309,6 +375,7 @@ function getEmailAuthRoutes(options) {
|
|
|
309
375
|
}
|
|
310
376
|
// Annotate the CommonJS export names for ESM import in node:
|
|
311
377
|
0 && (module.exports = {
|
|
378
|
+
AuthFetch,
|
|
312
379
|
checkAuthStatus,
|
|
313
380
|
getContext,
|
|
314
381
|
getEmailAuthRoutes
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import * as next_server from 'next/server';
|
|
2
2
|
import { InitRoutesOptions } from './types.mjs';
|
|
3
|
+
export { default as AuthFetch } from './server.mjs';
|
|
3
4
|
export { checkAuthStatus } from './token.mjs';
|
|
4
5
|
export { getContext } from './utils.mjs';
|
|
5
6
|
import '../types.mjs';
|
|
7
|
+
import 'react';
|
|
6
8
|
import '../../graphql/types.mjs';
|
|
7
9
|
|
|
8
10
|
/**
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import * as next_server from 'next/server';
|
|
2
2
|
import { InitRoutesOptions } from './types.js';
|
|
3
|
+
export { default as AuthFetch } from './server.js';
|
|
3
4
|
export { checkAuthStatus } from './token.js';
|
|
4
5
|
export { getContext } from './utils.js';
|
|
5
6
|
import '../types.js';
|
|
7
|
+
import 'react';
|
|
6
8
|
import '../../graphql/types.js';
|
|
7
9
|
|
|
8
10
|
/**
|
|
@@ -270,6 +270,65 @@ var getPutRoute = (options) => async (req) => {
|
|
|
270
270
|
return handleError(403, "Invalid password", options.onError);
|
|
271
271
|
};
|
|
272
272
|
|
|
273
|
+
// src/auth/email/server.tsx
|
|
274
|
+
import { AuthApply } from "naystack/auth/email/client";
|
|
275
|
+
import { cookies as cookies3 } from "next/headers";
|
|
276
|
+
|
|
277
|
+
// src/graphql/server.tsx
|
|
278
|
+
import {
|
|
279
|
+
ApolloClient,
|
|
280
|
+
HttpLink,
|
|
281
|
+
InMemoryCache
|
|
282
|
+
} from "@apollo/client";
|
|
283
|
+
import { registerApolloClient } from "@apollo/client-integration-nextjs";
|
|
284
|
+
import { cookies as cookies2 } from "next/headers";
|
|
285
|
+
import React2 from "react";
|
|
286
|
+
import { Suspense } from "react";
|
|
287
|
+
function Injector({
|
|
288
|
+
fetch: fetch2,
|
|
289
|
+
Component,
|
|
290
|
+
props
|
|
291
|
+
}) {
|
|
292
|
+
return /* @__PURE__ */ React2.createElement(Suspense, { fallback: /* @__PURE__ */ React2.createElement(Component, { ...props || {}, loading: true }) }, /* @__PURE__ */ React2.createElement(InjectorSuspensed, { Component, fetch: fetch2, props }));
|
|
293
|
+
}
|
|
294
|
+
async function InjectorSuspensed({
|
|
295
|
+
fetch: fetch2,
|
|
296
|
+
Component,
|
|
297
|
+
props
|
|
298
|
+
}) {
|
|
299
|
+
const data = await fetch2();
|
|
300
|
+
return /* @__PURE__ */ React2.createElement(Component, { loading: false, ...props || {}, data });
|
|
301
|
+
}
|
|
302
|
+
var { query: gqlQuery } = registerApolloClient(() => {
|
|
303
|
+
return new ApolloClient({
|
|
304
|
+
cache: new InMemoryCache(),
|
|
305
|
+
link: new HttpLink({
|
|
306
|
+
uri: getEnv("NEXT_PUBLIC_GRAPHQL_ENDPOINT" /* NEXT_PUBLIC_GRAPHQL_ENDPOINT */)
|
|
307
|
+
})
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
// src/auth/email/server.tsx
|
|
312
|
+
function AuthFetch() {
|
|
313
|
+
return /* @__PURE__ */ React.createElement(
|
|
314
|
+
Injector,
|
|
315
|
+
{
|
|
316
|
+
fetch: async () => {
|
|
317
|
+
const cookie = await cookies3();
|
|
318
|
+
const token = cookie.get("refresh");
|
|
319
|
+
if (!token) return null;
|
|
320
|
+
return fetch(process.env.NEXT_PUBLIC_BACKEND_BASE_URL + `/email`, {
|
|
321
|
+
credentials: "include",
|
|
322
|
+
headers: {
|
|
323
|
+
Cookie: cookie.toString()
|
|
324
|
+
}
|
|
325
|
+
}).then((res) => res.json()).then((data) => data.accessToken).catch(() => null);
|
|
326
|
+
},
|
|
327
|
+
Component: AuthApply
|
|
328
|
+
}
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
|
|
273
332
|
// src/auth/email/index.ts
|
|
274
333
|
function getEmailAuthRoutes(options) {
|
|
275
334
|
return {
|
|
@@ -280,6 +339,7 @@ function getEmailAuthRoutes(options) {
|
|
|
280
339
|
};
|
|
281
340
|
}
|
|
282
341
|
export {
|
|
342
|
+
AuthFetch,
|
|
283
343
|
checkAuthStatus,
|
|
284
344
|
getContext,
|
|
285
345
|
getEmailAuthRoutes
|
|
@@ -33,10 +33,15 @@ __export(server_exports, {
|
|
|
33
33
|
default: () => AuthFetch
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(server_exports);
|
|
36
|
+
var import_client2 = require("naystack/auth/email/client");
|
|
36
37
|
var import_headers2 = require("next/headers");
|
|
37
38
|
|
|
38
|
-
// src/
|
|
39
|
+
// src/graphql/server.tsx
|
|
40
|
+
var import_client = require("@apollo/client");
|
|
41
|
+
var import_client_integration_nextjs = require("@apollo/client-integration-nextjs");
|
|
42
|
+
var import_headers = require("next/headers");
|
|
39
43
|
var import_react = __toESM(require("react"));
|
|
44
|
+
var import_react2 = require("react");
|
|
40
45
|
|
|
41
46
|
// src/env.ts
|
|
42
47
|
var getEnvValue = (key) => {
|
|
@@ -87,37 +92,13 @@ function getEnv(key, skipCheck) {
|
|
|
87
92
|
return value;
|
|
88
93
|
}
|
|
89
94
|
|
|
90
|
-
// src/auth/email/client.tsx
|
|
91
|
-
var TokenContext = (0, import_react.createContext)({
|
|
92
|
-
token: null,
|
|
93
|
-
setToken: () => null
|
|
94
|
-
});
|
|
95
|
-
function AuthApply({ data }) {
|
|
96
|
-
const setToken = useSetToken();
|
|
97
|
-
(0, import_react.useEffect)(() => {
|
|
98
|
-
if (data) {
|
|
99
|
-
setToken(data);
|
|
100
|
-
}
|
|
101
|
-
}, [data]);
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
function useSetToken() {
|
|
105
|
-
const { setToken } = (0, import_react.useContext)(TokenContext);
|
|
106
|
-
return setToken;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
95
|
// src/graphql/server.tsx
|
|
110
|
-
var import_client = require("@apollo/client");
|
|
111
|
-
var import_client_integration_nextjs = require("@apollo/client-integration-nextjs");
|
|
112
|
-
var import_headers = require("next/headers");
|
|
113
|
-
var import_react2 = __toESM(require("react"));
|
|
114
|
-
var import_react3 = require("react");
|
|
115
96
|
function Injector({
|
|
116
97
|
fetch: fetch2,
|
|
117
98
|
Component,
|
|
118
99
|
props
|
|
119
100
|
}) {
|
|
120
|
-
return /* @__PURE__ */
|
|
101
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react2.Suspense, { fallback: /* @__PURE__ */ import_react.default.createElement(Component, { ...props || {}, loading: true }) }, /* @__PURE__ */ import_react.default.createElement(InjectorSuspensed, { Component, fetch: fetch2, props }));
|
|
121
102
|
}
|
|
122
103
|
async function InjectorSuspensed({
|
|
123
104
|
fetch: fetch2,
|
|
@@ -125,7 +106,7 @@ async function InjectorSuspensed({
|
|
|
125
106
|
props
|
|
126
107
|
}) {
|
|
127
108
|
const data = await fetch2();
|
|
128
|
-
return /* @__PURE__ */
|
|
109
|
+
return /* @__PURE__ */ import_react.default.createElement(Component, { loading: false, ...props || {}, data });
|
|
129
110
|
}
|
|
130
111
|
var { query: gqlQuery } = (0, import_client_integration_nextjs.registerApolloClient)(() => {
|
|
131
112
|
return new import_client.ApolloClient({
|
|
@@ -152,7 +133,7 @@ function AuthFetch() {
|
|
|
152
133
|
}
|
|
153
134
|
}).then((res) => res.json()).then((data) => data.accessToken).catch(() => null);
|
|
154
135
|
},
|
|
155
|
-
Component: AuthApply
|
|
136
|
+
Component: import_client2.AuthApply
|
|
156
137
|
}
|
|
157
138
|
);
|
|
158
139
|
}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
// src/auth/email/server.tsx
|
|
2
|
+
import { AuthApply } from "naystack/auth/email/client";
|
|
2
3
|
import { cookies as cookies2 } from "next/headers";
|
|
3
4
|
|
|
4
|
-
// src/
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} from "
|
|
5
|
+
// src/graphql/server.tsx
|
|
6
|
+
import {
|
|
7
|
+
ApolloClient,
|
|
8
|
+
HttpLink,
|
|
9
|
+
InMemoryCache
|
|
10
|
+
} from "@apollo/client";
|
|
11
|
+
import { registerApolloClient } from "@apollo/client-integration-nextjs";
|
|
12
|
+
import { cookies } from "next/headers";
|
|
13
|
+
import React2 from "react";
|
|
14
|
+
import { Suspense } from "react";
|
|
12
15
|
|
|
13
16
|
// src/env.ts
|
|
14
17
|
var getEnvValue = (key) => {
|
|
@@ -59,41 +62,13 @@ function getEnv(key, skipCheck) {
|
|
|
59
62
|
return value;
|
|
60
63
|
}
|
|
61
64
|
|
|
62
|
-
// src/auth/email/client.tsx
|
|
63
|
-
var TokenContext = createContext({
|
|
64
|
-
token: null,
|
|
65
|
-
setToken: () => null
|
|
66
|
-
});
|
|
67
|
-
function AuthApply({ data }) {
|
|
68
|
-
const setToken = useSetToken();
|
|
69
|
-
useEffect(() => {
|
|
70
|
-
if (data) {
|
|
71
|
-
setToken(data);
|
|
72
|
-
}
|
|
73
|
-
}, [data]);
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
function useSetToken() {
|
|
77
|
-
const { setToken } = useContext(TokenContext);
|
|
78
|
-
return setToken;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
65
|
// src/graphql/server.tsx
|
|
82
|
-
import {
|
|
83
|
-
ApolloClient,
|
|
84
|
-
HttpLink,
|
|
85
|
-
InMemoryCache
|
|
86
|
-
} from "@apollo/client";
|
|
87
|
-
import { registerApolloClient } from "@apollo/client-integration-nextjs";
|
|
88
|
-
import { cookies } from "next/headers";
|
|
89
|
-
import React3 from "react";
|
|
90
|
-
import { Suspense } from "react";
|
|
91
66
|
function Injector({
|
|
92
67
|
fetch: fetch2,
|
|
93
68
|
Component,
|
|
94
69
|
props
|
|
95
70
|
}) {
|
|
96
|
-
return /* @__PURE__ */
|
|
71
|
+
return /* @__PURE__ */ React2.createElement(Suspense, { fallback: /* @__PURE__ */ React2.createElement(Component, { ...props || {}, loading: true }) }, /* @__PURE__ */ React2.createElement(InjectorSuspensed, { Component, fetch: fetch2, props }));
|
|
97
72
|
}
|
|
98
73
|
async function InjectorSuspensed({
|
|
99
74
|
fetch: fetch2,
|
|
@@ -101,7 +76,7 @@ async function InjectorSuspensed({
|
|
|
101
76
|
props
|
|
102
77
|
}) {
|
|
103
78
|
const data = await fetch2();
|
|
104
|
-
return /* @__PURE__ */
|
|
79
|
+
return /* @__PURE__ */ React2.createElement(Component, { loading: false, ...props || {}, data });
|
|
105
80
|
}
|
|
106
81
|
var { query: gqlQuery } = registerApolloClient(() => {
|
|
107
82
|
return new ApolloClient({
|
package/dist/auth/index.cjs.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,11 +17,20 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/auth/index.ts
|
|
21
31
|
var auth_exports = {};
|
|
22
32
|
__export(auth_exports, {
|
|
33
|
+
AuthFetch: () => AuthFetch,
|
|
23
34
|
checkAuthStatus: () => checkAuthStatus,
|
|
24
35
|
getContext: () => getContext,
|
|
25
36
|
getEmailAuthRoutes: () => getEmailAuthRoutes,
|
|
@@ -314,6 +325,61 @@ var getPutRoute = (options) => async (req) => {
|
|
|
314
325
|
return handleError(403, "Invalid password", options.onError);
|
|
315
326
|
};
|
|
316
327
|
|
|
328
|
+
// src/auth/email/server.tsx
|
|
329
|
+
var import_client2 = require("naystack/auth/email/client");
|
|
330
|
+
var import_headers3 = require("next/headers");
|
|
331
|
+
|
|
332
|
+
// src/graphql/server.tsx
|
|
333
|
+
var import_client = require("@apollo/client");
|
|
334
|
+
var import_client_integration_nextjs = require("@apollo/client-integration-nextjs");
|
|
335
|
+
var import_headers2 = require("next/headers");
|
|
336
|
+
var import_react = __toESM(require("react"));
|
|
337
|
+
var import_react2 = require("react");
|
|
338
|
+
function Injector({
|
|
339
|
+
fetch: fetch2,
|
|
340
|
+
Component,
|
|
341
|
+
props
|
|
342
|
+
}) {
|
|
343
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react2.Suspense, { fallback: /* @__PURE__ */ import_react.default.createElement(Component, { ...props || {}, loading: true }) }, /* @__PURE__ */ import_react.default.createElement(InjectorSuspensed, { Component, fetch: fetch2, props }));
|
|
344
|
+
}
|
|
345
|
+
async function InjectorSuspensed({
|
|
346
|
+
fetch: fetch2,
|
|
347
|
+
Component,
|
|
348
|
+
props
|
|
349
|
+
}) {
|
|
350
|
+
const data = await fetch2();
|
|
351
|
+
return /* @__PURE__ */ import_react.default.createElement(Component, { loading: false, ...props || {}, data });
|
|
352
|
+
}
|
|
353
|
+
var { query: gqlQuery } = (0, import_client_integration_nextjs.registerApolloClient)(() => {
|
|
354
|
+
return new import_client.ApolloClient({
|
|
355
|
+
cache: new import_client.InMemoryCache(),
|
|
356
|
+
link: new import_client.HttpLink({
|
|
357
|
+
uri: getEnv("NEXT_PUBLIC_GRAPHQL_ENDPOINT" /* NEXT_PUBLIC_GRAPHQL_ENDPOINT */)
|
|
358
|
+
})
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
// src/auth/email/server.tsx
|
|
363
|
+
function AuthFetch() {
|
|
364
|
+
return /* @__PURE__ */ React.createElement(
|
|
365
|
+
Injector,
|
|
366
|
+
{
|
|
367
|
+
fetch: async () => {
|
|
368
|
+
const cookie = await (0, import_headers3.cookies)();
|
|
369
|
+
const token = cookie.get("refresh");
|
|
370
|
+
if (!token) return null;
|
|
371
|
+
return fetch(process.env.NEXT_PUBLIC_BACKEND_BASE_URL + `/email`, {
|
|
372
|
+
credentials: "include",
|
|
373
|
+
headers: {
|
|
374
|
+
Cookie: cookie.toString()
|
|
375
|
+
}
|
|
376
|
+
}).then((res) => res.json()).then((data) => data.accessToken).catch(() => null);
|
|
377
|
+
},
|
|
378
|
+
Component: import_client2.AuthApply
|
|
379
|
+
}
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
|
|
317
383
|
// src/auth/email/index.ts
|
|
318
384
|
function getEmailAuthRoutes(options) {
|
|
319
385
|
return {
|
|
@@ -326,7 +392,7 @@ function getEmailAuthRoutes(options) {
|
|
|
326
392
|
|
|
327
393
|
// src/auth/google/get.ts
|
|
328
394
|
var import_googleapis = require("googleapis");
|
|
329
|
-
var
|
|
395
|
+
var import_server5 = require("next/server");
|
|
330
396
|
var import_uuid = require("uuid");
|
|
331
397
|
var getGoogleGetRoute = ({
|
|
332
398
|
getUserIdFromEmail,
|
|
@@ -354,7 +420,7 @@ var getGoogleGetRoute = ({
|
|
|
354
420
|
prompt: "consent",
|
|
355
421
|
redirect_uri: url
|
|
356
422
|
});
|
|
357
|
-
const res =
|
|
423
|
+
const res = import_server5.NextResponse.redirect(authorizationUrl);
|
|
358
424
|
res.cookies.set("state", state2, {
|
|
359
425
|
httpOnly: true,
|
|
360
426
|
secure: true
|
|
@@ -363,12 +429,12 @@ var getGoogleGetRoute = ({
|
|
|
363
429
|
}
|
|
364
430
|
const errorURL = errorRedirectURL || redirectURL;
|
|
365
431
|
if (error) {
|
|
366
|
-
return
|
|
432
|
+
return import_server5.NextResponse.redirect(errorURL);
|
|
367
433
|
}
|
|
368
434
|
const state = req.nextUrl.searchParams.get("state") || void 0;
|
|
369
435
|
if (code && state) {
|
|
370
436
|
const localState = req.cookies.get("state")?.value;
|
|
371
|
-
if (localState !== state) return
|
|
437
|
+
if (localState !== state) return import_server5.NextResponse.redirect(errorURL);
|
|
372
438
|
const { tokens } = await oauth2Client.getToken(code);
|
|
373
439
|
oauth2Client.setCredentials(tokens);
|
|
374
440
|
const userInfoRequest = await import_googleapis.google.oauth2({
|
|
@@ -378,7 +444,7 @@ var getGoogleGetRoute = ({
|
|
|
378
444
|
const user = userInfoRequest.data;
|
|
379
445
|
if (user.email) {
|
|
380
446
|
const id = await getUserIdFromEmail(user);
|
|
381
|
-
const res =
|
|
447
|
+
const res = import_server5.NextResponse.redirect(redirectURL);
|
|
382
448
|
if (id) {
|
|
383
449
|
res.cookies.set(
|
|
384
450
|
REFRESH_COOKIE_NAME,
|
|
@@ -397,7 +463,7 @@ var getGoogleGetRoute = ({
|
|
|
397
463
|
return res;
|
|
398
464
|
}
|
|
399
465
|
}
|
|
400
|
-
return
|
|
466
|
+
return import_server5.NextResponse.redirect(errorURL);
|
|
401
467
|
};
|
|
402
468
|
};
|
|
403
469
|
|
|
@@ -409,7 +475,7 @@ function initGoogleAuth(props) {
|
|
|
409
475
|
}
|
|
410
476
|
|
|
411
477
|
// src/auth/instagram/route.ts
|
|
412
|
-
var
|
|
478
|
+
var import_server7 = require("next/server");
|
|
413
479
|
|
|
414
480
|
// src/auth/instagram/utils.ts
|
|
415
481
|
async function getRefreshedInstagramAccessToken(token) {
|
|
@@ -471,7 +537,7 @@ var getInstagramUser = (token, id, fields) => {
|
|
|
471
537
|
};
|
|
472
538
|
|
|
473
539
|
// src/socials/meta-webhook.ts
|
|
474
|
-
var
|
|
540
|
+
var import_server6 = require("next/server");
|
|
475
541
|
|
|
476
542
|
// src/auth/instagram/route.ts
|
|
477
543
|
var getInstagramRoute = ({
|
|
@@ -479,7 +545,7 @@ var getInstagramRoute = ({
|
|
|
479
545
|
errorRedirectURL,
|
|
480
546
|
onUser
|
|
481
547
|
}) => {
|
|
482
|
-
const handleError2 = (message) =>
|
|
548
|
+
const handleError2 = (message) => import_server7.NextResponse.redirect(`${errorRedirectURL}?error=${message}`);
|
|
483
549
|
return async (req) => {
|
|
484
550
|
const accessCode = req.nextUrl.searchParams.get("code");
|
|
485
551
|
const error = req.nextUrl.searchParams.get("error");
|
|
@@ -503,7 +569,7 @@ var getInstagramRoute = ({
|
|
|
503
569
|
instagramData.accessToken
|
|
504
570
|
);
|
|
505
571
|
if (errorMessage) return handleError2(errorMessage);
|
|
506
|
-
return
|
|
572
|
+
return import_server7.NextResponse.redirect(redirectURL);
|
|
507
573
|
};
|
|
508
574
|
};
|
|
509
575
|
|
|
@@ -515,13 +581,14 @@ function initInstagramAuth(props) {
|
|
|
515
581
|
}
|
|
516
582
|
|
|
517
583
|
// src/auth/utils/token.ts
|
|
518
|
-
var
|
|
584
|
+
var import_headers4 = require("next/headers");
|
|
519
585
|
async function getRefreshToken() {
|
|
520
|
-
const Cookie = await (0,
|
|
586
|
+
const Cookie = await (0, import_headers4.cookies)();
|
|
521
587
|
return Cookie.get(REFRESH_COOKIE_NAME)?.value || null;
|
|
522
588
|
}
|
|
523
589
|
// Annotate the CommonJS export names for ESM import in node:
|
|
524
590
|
0 && (module.exports = {
|
|
591
|
+
AuthFetch,
|
|
525
592
|
checkAuthStatus,
|
|
526
593
|
getContext,
|
|
527
594
|
getEmailAuthRoutes,
|
package/dist/auth/index.d.mts
CHANGED
|
@@ -2,6 +2,7 @@ export { getEmailAuthRoutes } from './email/index.mjs';
|
|
|
2
2
|
export { initGoogleAuth } from './google/index.mjs';
|
|
3
3
|
export { initInstagramAuth } from './instagram/index.mjs';
|
|
4
4
|
export { getRefreshToken } from './utils/token.mjs';
|
|
5
|
+
export { default as AuthFetch } from './email/server.mjs';
|
|
5
6
|
export { checkAuthStatus } from './email/token.mjs';
|
|
6
7
|
export { getContext } from './email/utils.mjs';
|
|
7
8
|
export { getRefreshedInstagramAccessToken } from './instagram/utils.mjs';
|
|
@@ -10,4 +11,5 @@ import './email/types.mjs';
|
|
|
10
11
|
import './types.mjs';
|
|
11
12
|
import 'googleapis';
|
|
12
13
|
import '../socials/instagram/types.mjs';
|
|
14
|
+
import 'react';
|
|
13
15
|
import '../graphql/types.mjs';
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { getEmailAuthRoutes } from './email/index.js';
|
|
|
2
2
|
export { initGoogleAuth } from './google/index.js';
|
|
3
3
|
export { initInstagramAuth } from './instagram/index.js';
|
|
4
4
|
export { getRefreshToken } from './utils/token.js';
|
|
5
|
+
export { default as AuthFetch } from './email/server.js';
|
|
5
6
|
export { checkAuthStatus } from './email/token.js';
|
|
6
7
|
export { getContext } from './email/utils.js';
|
|
7
8
|
export { getRefreshedInstagramAccessToken } from './instagram/utils.js';
|
|
@@ -10,4 +11,5 @@ import './email/types.js';
|
|
|
10
11
|
import './types.js';
|
|
11
12
|
import 'googleapis';
|
|
12
13
|
import '../socials/instagram/types.js';
|
|
14
|
+
import 'react';
|
|
13
15
|
import '../graphql/types.js';
|
package/dist/auth/index.esm.js
CHANGED
|
@@ -282,6 +282,65 @@ var getPutRoute = (options) => async (req) => {
|
|
|
282
282
|
return handleError(403, "Invalid password", options.onError);
|
|
283
283
|
};
|
|
284
284
|
|
|
285
|
+
// src/auth/email/server.tsx
|
|
286
|
+
import { AuthApply } from "naystack/auth/email/client";
|
|
287
|
+
import { cookies as cookies3 } from "next/headers";
|
|
288
|
+
|
|
289
|
+
// src/graphql/server.tsx
|
|
290
|
+
import {
|
|
291
|
+
ApolloClient,
|
|
292
|
+
HttpLink,
|
|
293
|
+
InMemoryCache
|
|
294
|
+
} from "@apollo/client";
|
|
295
|
+
import { registerApolloClient } from "@apollo/client-integration-nextjs";
|
|
296
|
+
import { cookies as cookies2 } from "next/headers";
|
|
297
|
+
import React2 from "react";
|
|
298
|
+
import { Suspense } from "react";
|
|
299
|
+
function Injector({
|
|
300
|
+
fetch: fetch2,
|
|
301
|
+
Component,
|
|
302
|
+
props
|
|
303
|
+
}) {
|
|
304
|
+
return /* @__PURE__ */ React2.createElement(Suspense, { fallback: /* @__PURE__ */ React2.createElement(Component, { ...props || {}, loading: true }) }, /* @__PURE__ */ React2.createElement(InjectorSuspensed, { Component, fetch: fetch2, props }));
|
|
305
|
+
}
|
|
306
|
+
async function InjectorSuspensed({
|
|
307
|
+
fetch: fetch2,
|
|
308
|
+
Component,
|
|
309
|
+
props
|
|
310
|
+
}) {
|
|
311
|
+
const data = await fetch2();
|
|
312
|
+
return /* @__PURE__ */ React2.createElement(Component, { loading: false, ...props || {}, data });
|
|
313
|
+
}
|
|
314
|
+
var { query: gqlQuery } = registerApolloClient(() => {
|
|
315
|
+
return new ApolloClient({
|
|
316
|
+
cache: new InMemoryCache(),
|
|
317
|
+
link: new HttpLink({
|
|
318
|
+
uri: getEnv("NEXT_PUBLIC_GRAPHQL_ENDPOINT" /* NEXT_PUBLIC_GRAPHQL_ENDPOINT */)
|
|
319
|
+
})
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
// src/auth/email/server.tsx
|
|
324
|
+
function AuthFetch() {
|
|
325
|
+
return /* @__PURE__ */ React.createElement(
|
|
326
|
+
Injector,
|
|
327
|
+
{
|
|
328
|
+
fetch: async () => {
|
|
329
|
+
const cookie = await cookies3();
|
|
330
|
+
const token = cookie.get("refresh");
|
|
331
|
+
if (!token) return null;
|
|
332
|
+
return fetch(process.env.NEXT_PUBLIC_BACKEND_BASE_URL + `/email`, {
|
|
333
|
+
credentials: "include",
|
|
334
|
+
headers: {
|
|
335
|
+
Cookie: cookie.toString()
|
|
336
|
+
}
|
|
337
|
+
}).then((res) => res.json()).then((data) => data.accessToken).catch(() => null);
|
|
338
|
+
},
|
|
339
|
+
Component: AuthApply
|
|
340
|
+
}
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
|
|
285
344
|
// src/auth/email/index.ts
|
|
286
345
|
function getEmailAuthRoutes(options) {
|
|
287
346
|
return {
|
|
@@ -483,12 +542,13 @@ function initInstagramAuth(props) {
|
|
|
483
542
|
}
|
|
484
543
|
|
|
485
544
|
// src/auth/utils/token.ts
|
|
486
|
-
import { cookies as
|
|
545
|
+
import { cookies as cookies4 } from "next/headers";
|
|
487
546
|
async function getRefreshToken() {
|
|
488
|
-
const Cookie = await
|
|
547
|
+
const Cookie = await cookies4();
|
|
489
548
|
return Cookie.get(REFRESH_COOKIE_NAME)?.value || null;
|
|
490
549
|
}
|
|
491
550
|
export {
|
|
551
|
+
AuthFetch,
|
|
492
552
|
checkAuthStatus,
|
|
493
553
|
getContext,
|
|
494
554
|
getEmailAuthRoutes,
|