naystack 1.5.18 → 1.5.19
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 +86 -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 +85 -0
- package/dist/auth/index.cjs.js +98 -12
- package/dist/auth/index.d.mts +2 -0
- package/dist/auth/index.d.ts +2 -0
- package/dist/auth/index.esm.js +87 -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,80 @@ 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_headers3 = require("next/headers");
|
|
314
|
+
|
|
315
|
+
// src/auth/email/client.tsx
|
|
316
|
+
var import_react = __toESM(require("react"));
|
|
317
|
+
var TokenContext = (0, import_react.createContext)({
|
|
318
|
+
token: null,
|
|
319
|
+
setToken: () => null
|
|
320
|
+
});
|
|
321
|
+
function AuthApply({ data }) {
|
|
322
|
+
const setToken = useSetToken();
|
|
323
|
+
(0, import_react.useEffect)(() => {
|
|
324
|
+
if (data) {
|
|
325
|
+
setToken(data);
|
|
326
|
+
}
|
|
327
|
+
}, [data]);
|
|
328
|
+
return null;
|
|
329
|
+
}
|
|
330
|
+
function useSetToken() {
|
|
331
|
+
const { setToken } = (0, import_react.useContext)(TokenContext);
|
|
332
|
+
return setToken;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// src/graphql/server.tsx
|
|
336
|
+
var import_client = require("@apollo/client");
|
|
337
|
+
var import_client_integration_nextjs = require("@apollo/client-integration-nextjs");
|
|
338
|
+
var import_headers2 = require("next/headers");
|
|
339
|
+
var import_react2 = __toESM(require("react"));
|
|
340
|
+
var import_react3 = require("react");
|
|
341
|
+
function Injector({
|
|
342
|
+
fetch: fetch2,
|
|
343
|
+
Component,
|
|
344
|
+
props
|
|
345
|
+
}) {
|
|
346
|
+
return /* @__PURE__ */ import_react2.default.createElement(import_react3.Suspense, { fallback: /* @__PURE__ */ import_react2.default.createElement(Component, { ...props || {}, loading: true }) }, /* @__PURE__ */ import_react2.default.createElement(InjectorSuspensed, { Component, fetch: fetch2, props }));
|
|
347
|
+
}
|
|
348
|
+
async function InjectorSuspensed({
|
|
349
|
+
fetch: fetch2,
|
|
350
|
+
Component,
|
|
351
|
+
props
|
|
352
|
+
}) {
|
|
353
|
+
const data = await fetch2();
|
|
354
|
+
return /* @__PURE__ */ import_react2.default.createElement(Component, { loading: false, ...props || {}, data });
|
|
355
|
+
}
|
|
356
|
+
var { query: gqlQuery } = (0, import_client_integration_nextjs.registerApolloClient)(() => {
|
|
357
|
+
return new import_client.ApolloClient({
|
|
358
|
+
cache: new import_client.InMemoryCache(),
|
|
359
|
+
link: new import_client.HttpLink({
|
|
360
|
+
uri: getEnv("NEXT_PUBLIC_GRAPHQL_ENDPOINT" /* NEXT_PUBLIC_GRAPHQL_ENDPOINT */)
|
|
361
|
+
})
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
// src/auth/email/server.tsx
|
|
366
|
+
function AuthFetch() {
|
|
367
|
+
return /* @__PURE__ */ React.createElement(
|
|
368
|
+
Injector,
|
|
369
|
+
{
|
|
370
|
+
fetch: async () => {
|
|
371
|
+
const cookie = await (0, import_headers3.cookies)();
|
|
372
|
+
const token = cookie.get("refresh");
|
|
373
|
+
if (!token) return null;
|
|
374
|
+
return fetch(process.env.NEXT_PUBLIC_BACKEND_BASE_URL + `/email`, {
|
|
375
|
+
credentials: "include",
|
|
376
|
+
headers: {
|
|
377
|
+
Cookie: cookie.toString()
|
|
378
|
+
}
|
|
379
|
+
}).then((res) => res.json()).then((data) => data.accessToken).catch(() => null);
|
|
380
|
+
},
|
|
381
|
+
Component: AuthApply
|
|
382
|
+
}
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
|
|
301
386
|
// src/auth/email/index.ts
|
|
302
387
|
function getEmailAuthRoutes(options) {
|
|
303
388
|
return {
|
|
@@ -309,6 +394,7 @@ function getEmailAuthRoutes(options) {
|
|
|
309
394
|
}
|
|
310
395
|
// Annotate the CommonJS export names for ESM import in node:
|
|
311
396
|
0 && (module.exports = {
|
|
397
|
+
AuthFetch,
|
|
312
398
|
checkAuthStatus,
|
|
313
399
|
getContext,
|
|
314
400
|
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,90 @@ 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 { cookies as cookies3 } from "next/headers";
|
|
275
|
+
|
|
276
|
+
// src/auth/email/client.tsx
|
|
277
|
+
import React2, {
|
|
278
|
+
createContext,
|
|
279
|
+
useCallback,
|
|
280
|
+
useContext,
|
|
281
|
+
useEffect,
|
|
282
|
+
useState
|
|
283
|
+
} from "react";
|
|
284
|
+
var TokenContext = createContext({
|
|
285
|
+
token: null,
|
|
286
|
+
setToken: () => null
|
|
287
|
+
});
|
|
288
|
+
function AuthApply({ data }) {
|
|
289
|
+
const setToken = useSetToken();
|
|
290
|
+
useEffect(() => {
|
|
291
|
+
if (data) {
|
|
292
|
+
setToken(data);
|
|
293
|
+
}
|
|
294
|
+
}, [data]);
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
function useSetToken() {
|
|
298
|
+
const { setToken } = useContext(TokenContext);
|
|
299
|
+
return setToken;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// src/graphql/server.tsx
|
|
303
|
+
import {
|
|
304
|
+
ApolloClient,
|
|
305
|
+
HttpLink,
|
|
306
|
+
InMemoryCache
|
|
307
|
+
} from "@apollo/client";
|
|
308
|
+
import { registerApolloClient } from "@apollo/client-integration-nextjs";
|
|
309
|
+
import { cookies as cookies2 } from "next/headers";
|
|
310
|
+
import React3 from "react";
|
|
311
|
+
import { Suspense } from "react";
|
|
312
|
+
function Injector({
|
|
313
|
+
fetch: fetch2,
|
|
314
|
+
Component,
|
|
315
|
+
props
|
|
316
|
+
}) {
|
|
317
|
+
return /* @__PURE__ */ React3.createElement(Suspense, { fallback: /* @__PURE__ */ React3.createElement(Component, { ...props || {}, loading: true }) }, /* @__PURE__ */ React3.createElement(InjectorSuspensed, { Component, fetch: fetch2, props }));
|
|
318
|
+
}
|
|
319
|
+
async function InjectorSuspensed({
|
|
320
|
+
fetch: fetch2,
|
|
321
|
+
Component,
|
|
322
|
+
props
|
|
323
|
+
}) {
|
|
324
|
+
const data = await fetch2();
|
|
325
|
+
return /* @__PURE__ */ React3.createElement(Component, { loading: false, ...props || {}, data });
|
|
326
|
+
}
|
|
327
|
+
var { query: gqlQuery } = registerApolloClient(() => {
|
|
328
|
+
return new ApolloClient({
|
|
329
|
+
cache: new InMemoryCache(),
|
|
330
|
+
link: new HttpLink({
|
|
331
|
+
uri: getEnv("NEXT_PUBLIC_GRAPHQL_ENDPOINT" /* NEXT_PUBLIC_GRAPHQL_ENDPOINT */)
|
|
332
|
+
})
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
// src/auth/email/server.tsx
|
|
337
|
+
function AuthFetch() {
|
|
338
|
+
return /* @__PURE__ */ React.createElement(
|
|
339
|
+
Injector,
|
|
340
|
+
{
|
|
341
|
+
fetch: async () => {
|
|
342
|
+
const cookie = await cookies3();
|
|
343
|
+
const token = cookie.get("refresh");
|
|
344
|
+
if (!token) return null;
|
|
345
|
+
return fetch(process.env.NEXT_PUBLIC_BACKEND_BASE_URL + `/email`, {
|
|
346
|
+
credentials: "include",
|
|
347
|
+
headers: {
|
|
348
|
+
Cookie: cookie.toString()
|
|
349
|
+
}
|
|
350
|
+
}).then((res) => res.json()).then((data) => data.accessToken).catch(() => null);
|
|
351
|
+
},
|
|
352
|
+
Component: AuthApply
|
|
353
|
+
}
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
|
|
273
357
|
// src/auth/email/index.ts
|
|
274
358
|
function getEmailAuthRoutes(options) {
|
|
275
359
|
return {
|
|
@@ -280,6 +364,7 @@ function getEmailAuthRoutes(options) {
|
|
|
280
364
|
};
|
|
281
365
|
}
|
|
282
366
|
export {
|
|
367
|
+
AuthFetch,
|
|
283
368
|
checkAuthStatus,
|
|
284
369
|
getContext,
|
|
285
370
|
getEmailAuthRoutes
|
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,80 @@ 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_headers3 = require("next/headers");
|
|
330
|
+
|
|
331
|
+
// src/auth/email/client.tsx
|
|
332
|
+
var import_react = __toESM(require("react"));
|
|
333
|
+
var TokenContext = (0, import_react.createContext)({
|
|
334
|
+
token: null,
|
|
335
|
+
setToken: () => null
|
|
336
|
+
});
|
|
337
|
+
function AuthApply({ data }) {
|
|
338
|
+
const setToken = useSetToken();
|
|
339
|
+
(0, import_react.useEffect)(() => {
|
|
340
|
+
if (data) {
|
|
341
|
+
setToken(data);
|
|
342
|
+
}
|
|
343
|
+
}, [data]);
|
|
344
|
+
return null;
|
|
345
|
+
}
|
|
346
|
+
function useSetToken() {
|
|
347
|
+
const { setToken } = (0, import_react.useContext)(TokenContext);
|
|
348
|
+
return setToken;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// src/graphql/server.tsx
|
|
352
|
+
var import_client = require("@apollo/client");
|
|
353
|
+
var import_client_integration_nextjs = require("@apollo/client-integration-nextjs");
|
|
354
|
+
var import_headers2 = require("next/headers");
|
|
355
|
+
var import_react2 = __toESM(require("react"));
|
|
356
|
+
var import_react3 = require("react");
|
|
357
|
+
function Injector({
|
|
358
|
+
fetch: fetch2,
|
|
359
|
+
Component,
|
|
360
|
+
props
|
|
361
|
+
}) {
|
|
362
|
+
return /* @__PURE__ */ import_react2.default.createElement(import_react3.Suspense, { fallback: /* @__PURE__ */ import_react2.default.createElement(Component, { ...props || {}, loading: true }) }, /* @__PURE__ */ import_react2.default.createElement(InjectorSuspensed, { Component, fetch: fetch2, props }));
|
|
363
|
+
}
|
|
364
|
+
async function InjectorSuspensed({
|
|
365
|
+
fetch: fetch2,
|
|
366
|
+
Component,
|
|
367
|
+
props
|
|
368
|
+
}) {
|
|
369
|
+
const data = await fetch2();
|
|
370
|
+
return /* @__PURE__ */ import_react2.default.createElement(Component, { loading: false, ...props || {}, data });
|
|
371
|
+
}
|
|
372
|
+
var { query: gqlQuery } = (0, import_client_integration_nextjs.registerApolloClient)(() => {
|
|
373
|
+
return new import_client.ApolloClient({
|
|
374
|
+
cache: new import_client.InMemoryCache(),
|
|
375
|
+
link: new import_client.HttpLink({
|
|
376
|
+
uri: getEnv("NEXT_PUBLIC_GRAPHQL_ENDPOINT" /* NEXT_PUBLIC_GRAPHQL_ENDPOINT */)
|
|
377
|
+
})
|
|
378
|
+
});
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
// src/auth/email/server.tsx
|
|
382
|
+
function AuthFetch() {
|
|
383
|
+
return /* @__PURE__ */ React.createElement(
|
|
384
|
+
Injector,
|
|
385
|
+
{
|
|
386
|
+
fetch: async () => {
|
|
387
|
+
const cookie = await (0, import_headers3.cookies)();
|
|
388
|
+
const token = cookie.get("refresh");
|
|
389
|
+
if (!token) return null;
|
|
390
|
+
return fetch(process.env.NEXT_PUBLIC_BACKEND_BASE_URL + `/email`, {
|
|
391
|
+
credentials: "include",
|
|
392
|
+
headers: {
|
|
393
|
+
Cookie: cookie.toString()
|
|
394
|
+
}
|
|
395
|
+
}).then((res) => res.json()).then((data) => data.accessToken).catch(() => null);
|
|
396
|
+
},
|
|
397
|
+
Component: AuthApply
|
|
398
|
+
}
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
|
|
317
402
|
// src/auth/email/index.ts
|
|
318
403
|
function getEmailAuthRoutes(options) {
|
|
319
404
|
return {
|
|
@@ -326,7 +411,7 @@ function getEmailAuthRoutes(options) {
|
|
|
326
411
|
|
|
327
412
|
// src/auth/google/get.ts
|
|
328
413
|
var import_googleapis = require("googleapis");
|
|
329
|
-
var
|
|
414
|
+
var import_server5 = require("next/server");
|
|
330
415
|
var import_uuid = require("uuid");
|
|
331
416
|
var getGoogleGetRoute = ({
|
|
332
417
|
getUserIdFromEmail,
|
|
@@ -354,7 +439,7 @@ var getGoogleGetRoute = ({
|
|
|
354
439
|
prompt: "consent",
|
|
355
440
|
redirect_uri: url
|
|
356
441
|
});
|
|
357
|
-
const res =
|
|
442
|
+
const res = import_server5.NextResponse.redirect(authorizationUrl);
|
|
358
443
|
res.cookies.set("state", state2, {
|
|
359
444
|
httpOnly: true,
|
|
360
445
|
secure: true
|
|
@@ -363,12 +448,12 @@ var getGoogleGetRoute = ({
|
|
|
363
448
|
}
|
|
364
449
|
const errorURL = errorRedirectURL || redirectURL;
|
|
365
450
|
if (error) {
|
|
366
|
-
return
|
|
451
|
+
return import_server5.NextResponse.redirect(errorURL);
|
|
367
452
|
}
|
|
368
453
|
const state = req.nextUrl.searchParams.get("state") || void 0;
|
|
369
454
|
if (code && state) {
|
|
370
455
|
const localState = req.cookies.get("state")?.value;
|
|
371
|
-
if (localState !== state) return
|
|
456
|
+
if (localState !== state) return import_server5.NextResponse.redirect(errorURL);
|
|
372
457
|
const { tokens } = await oauth2Client.getToken(code);
|
|
373
458
|
oauth2Client.setCredentials(tokens);
|
|
374
459
|
const userInfoRequest = await import_googleapis.google.oauth2({
|
|
@@ -378,7 +463,7 @@ var getGoogleGetRoute = ({
|
|
|
378
463
|
const user = userInfoRequest.data;
|
|
379
464
|
if (user.email) {
|
|
380
465
|
const id = await getUserIdFromEmail(user);
|
|
381
|
-
const res =
|
|
466
|
+
const res = import_server5.NextResponse.redirect(redirectURL);
|
|
382
467
|
if (id) {
|
|
383
468
|
res.cookies.set(
|
|
384
469
|
REFRESH_COOKIE_NAME,
|
|
@@ -397,7 +482,7 @@ var getGoogleGetRoute = ({
|
|
|
397
482
|
return res;
|
|
398
483
|
}
|
|
399
484
|
}
|
|
400
|
-
return
|
|
485
|
+
return import_server5.NextResponse.redirect(errorURL);
|
|
401
486
|
};
|
|
402
487
|
};
|
|
403
488
|
|
|
@@ -409,7 +494,7 @@ function initGoogleAuth(props) {
|
|
|
409
494
|
}
|
|
410
495
|
|
|
411
496
|
// src/auth/instagram/route.ts
|
|
412
|
-
var
|
|
497
|
+
var import_server7 = require("next/server");
|
|
413
498
|
|
|
414
499
|
// src/auth/instagram/utils.ts
|
|
415
500
|
async function getRefreshedInstagramAccessToken(token) {
|
|
@@ -471,7 +556,7 @@ var getInstagramUser = (token, id, fields) => {
|
|
|
471
556
|
};
|
|
472
557
|
|
|
473
558
|
// src/socials/meta-webhook.ts
|
|
474
|
-
var
|
|
559
|
+
var import_server6 = require("next/server");
|
|
475
560
|
|
|
476
561
|
// src/auth/instagram/route.ts
|
|
477
562
|
var getInstagramRoute = ({
|
|
@@ -479,7 +564,7 @@ var getInstagramRoute = ({
|
|
|
479
564
|
errorRedirectURL,
|
|
480
565
|
onUser
|
|
481
566
|
}) => {
|
|
482
|
-
const handleError2 = (message) =>
|
|
567
|
+
const handleError2 = (message) => import_server7.NextResponse.redirect(`${errorRedirectURL}?error=${message}`);
|
|
483
568
|
return async (req) => {
|
|
484
569
|
const accessCode = req.nextUrl.searchParams.get("code");
|
|
485
570
|
const error = req.nextUrl.searchParams.get("error");
|
|
@@ -503,7 +588,7 @@ var getInstagramRoute = ({
|
|
|
503
588
|
instagramData.accessToken
|
|
504
589
|
);
|
|
505
590
|
if (errorMessage) return handleError2(errorMessage);
|
|
506
|
-
return
|
|
591
|
+
return import_server7.NextResponse.redirect(redirectURL);
|
|
507
592
|
};
|
|
508
593
|
};
|
|
509
594
|
|
|
@@ -515,13 +600,14 @@ function initInstagramAuth(props) {
|
|
|
515
600
|
}
|
|
516
601
|
|
|
517
602
|
// src/auth/utils/token.ts
|
|
518
|
-
var
|
|
603
|
+
var import_headers4 = require("next/headers");
|
|
519
604
|
async function getRefreshToken() {
|
|
520
|
-
const Cookie = await (0,
|
|
605
|
+
const Cookie = await (0, import_headers4.cookies)();
|
|
521
606
|
return Cookie.get(REFRESH_COOKIE_NAME)?.value || null;
|
|
522
607
|
}
|
|
523
608
|
// Annotate the CommonJS export names for ESM import in node:
|
|
524
609
|
0 && (module.exports = {
|
|
610
|
+
AuthFetch,
|
|
525
611
|
checkAuthStatus,
|
|
526
612
|
getContext,
|
|
527
613
|
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,90 @@ 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 { cookies as cookies3 } from "next/headers";
|
|
287
|
+
|
|
288
|
+
// src/auth/email/client.tsx
|
|
289
|
+
import React2, {
|
|
290
|
+
createContext,
|
|
291
|
+
useCallback,
|
|
292
|
+
useContext,
|
|
293
|
+
useEffect,
|
|
294
|
+
useState
|
|
295
|
+
} from "react";
|
|
296
|
+
var TokenContext = createContext({
|
|
297
|
+
token: null,
|
|
298
|
+
setToken: () => null
|
|
299
|
+
});
|
|
300
|
+
function AuthApply({ data }) {
|
|
301
|
+
const setToken = useSetToken();
|
|
302
|
+
useEffect(() => {
|
|
303
|
+
if (data) {
|
|
304
|
+
setToken(data);
|
|
305
|
+
}
|
|
306
|
+
}, [data]);
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
function useSetToken() {
|
|
310
|
+
const { setToken } = useContext(TokenContext);
|
|
311
|
+
return setToken;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// src/graphql/server.tsx
|
|
315
|
+
import {
|
|
316
|
+
ApolloClient,
|
|
317
|
+
HttpLink,
|
|
318
|
+
InMemoryCache
|
|
319
|
+
} from "@apollo/client";
|
|
320
|
+
import { registerApolloClient } from "@apollo/client-integration-nextjs";
|
|
321
|
+
import { cookies as cookies2 } from "next/headers";
|
|
322
|
+
import React3 from "react";
|
|
323
|
+
import { Suspense } from "react";
|
|
324
|
+
function Injector({
|
|
325
|
+
fetch: fetch2,
|
|
326
|
+
Component,
|
|
327
|
+
props
|
|
328
|
+
}) {
|
|
329
|
+
return /* @__PURE__ */ React3.createElement(Suspense, { fallback: /* @__PURE__ */ React3.createElement(Component, { ...props || {}, loading: true }) }, /* @__PURE__ */ React3.createElement(InjectorSuspensed, { Component, fetch: fetch2, props }));
|
|
330
|
+
}
|
|
331
|
+
async function InjectorSuspensed({
|
|
332
|
+
fetch: fetch2,
|
|
333
|
+
Component,
|
|
334
|
+
props
|
|
335
|
+
}) {
|
|
336
|
+
const data = await fetch2();
|
|
337
|
+
return /* @__PURE__ */ React3.createElement(Component, { loading: false, ...props || {}, data });
|
|
338
|
+
}
|
|
339
|
+
var { query: gqlQuery } = registerApolloClient(() => {
|
|
340
|
+
return new ApolloClient({
|
|
341
|
+
cache: new InMemoryCache(),
|
|
342
|
+
link: new HttpLink({
|
|
343
|
+
uri: getEnv("NEXT_PUBLIC_GRAPHQL_ENDPOINT" /* NEXT_PUBLIC_GRAPHQL_ENDPOINT */)
|
|
344
|
+
})
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
// src/auth/email/server.tsx
|
|
349
|
+
function AuthFetch() {
|
|
350
|
+
return /* @__PURE__ */ React.createElement(
|
|
351
|
+
Injector,
|
|
352
|
+
{
|
|
353
|
+
fetch: async () => {
|
|
354
|
+
const cookie = await cookies3();
|
|
355
|
+
const token = cookie.get("refresh");
|
|
356
|
+
if (!token) return null;
|
|
357
|
+
return fetch(process.env.NEXT_PUBLIC_BACKEND_BASE_URL + `/email`, {
|
|
358
|
+
credentials: "include",
|
|
359
|
+
headers: {
|
|
360
|
+
Cookie: cookie.toString()
|
|
361
|
+
}
|
|
362
|
+
}).then((res) => res.json()).then((data) => data.accessToken).catch(() => null);
|
|
363
|
+
},
|
|
364
|
+
Component: AuthApply
|
|
365
|
+
}
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
|
|
285
369
|
// src/auth/email/index.ts
|
|
286
370
|
function getEmailAuthRoutes(options) {
|
|
287
371
|
return {
|
|
@@ -483,12 +567,13 @@ function initInstagramAuth(props) {
|
|
|
483
567
|
}
|
|
484
568
|
|
|
485
569
|
// src/auth/utils/token.ts
|
|
486
|
-
import { cookies as
|
|
570
|
+
import { cookies as cookies4 } from "next/headers";
|
|
487
571
|
async function getRefreshToken() {
|
|
488
|
-
const Cookie = await
|
|
572
|
+
const Cookie = await cookies4();
|
|
489
573
|
return Cookie.get(REFRESH_COOKIE_NAME)?.value || null;
|
|
490
574
|
}
|
|
491
575
|
export {
|
|
576
|
+
AuthFetch,
|
|
492
577
|
checkAuthStatus,
|
|
493
578
|
getContext,
|
|
494
579
|
getEmailAuthRoutes,
|