naystack 1.5.25 → 1.5.26
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 +45 -4
- package/dist/auth/email/index.d.mts +6 -5
- package/dist/auth/email/index.d.ts +6 -5
- package/dist/auth/email/index.esm.js +47 -4
- package/dist/auth/email/types.d.mts +1 -0
- package/dist/auth/email/types.d.ts +1 -0
- package/dist/auth/index.cjs.js +57 -14
- package/dist/auth/index.esm.js +57 -14
- package/package.json +1 -1
|
@@ -36,6 +36,7 @@ __export(email_exports, {
|
|
|
36
36
|
getEmailAuthRoutes: () => getEmailAuthRoutes
|
|
37
37
|
});
|
|
38
38
|
module.exports = __toCommonJS(email_exports);
|
|
39
|
+
var import_server4 = require("next/server");
|
|
39
40
|
|
|
40
41
|
// src/auth/email/token.ts
|
|
41
42
|
var import_bcryptjs = require("bcryptjs");
|
|
@@ -366,12 +367,52 @@ function AuthFetch() {
|
|
|
366
367
|
}
|
|
367
368
|
|
|
368
369
|
// src/auth/email/index.ts
|
|
370
|
+
function getCorsHeaders(origin, allowedOrigins) {
|
|
371
|
+
if (!origin || !allowedOrigins.includes(origin)) return null;
|
|
372
|
+
return {
|
|
373
|
+
"Access-Control-Allow-Origin": origin,
|
|
374
|
+
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
|
|
375
|
+
"Access-Control-Allow-Headers": "Content-Type, Authorization",
|
|
376
|
+
"Access-Control-Allow-Credentials": "true"
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
function withCors(handler, allowedOrigins) {
|
|
380
|
+
if (!allowedOrigins?.length) return handler;
|
|
381
|
+
return ((req) => {
|
|
382
|
+
return handler(req).then((response) => {
|
|
383
|
+
if (!response) return response;
|
|
384
|
+
const corsHeaders = getCorsHeaders(
|
|
385
|
+
req.headers.get("origin"),
|
|
386
|
+
allowedOrigins
|
|
387
|
+
);
|
|
388
|
+
if (corsHeaders) {
|
|
389
|
+
Object.entries(corsHeaders).forEach(([key, value]) => {
|
|
390
|
+
response.headers.set(key, value);
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
return response;
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
}
|
|
369
397
|
function getEmailAuthRoutes(options) {
|
|
398
|
+
const { allowedOrigins } = options;
|
|
370
399
|
return {
|
|
371
|
-
GET: getGetRoute(options),
|
|
372
|
-
POST: getPostRoute(options),
|
|
373
|
-
PUT: getPutRoute(options),
|
|
374
|
-
DELETE: getDeleteRoute(options)
|
|
400
|
+
GET: withCors(getGetRoute(options), allowedOrigins),
|
|
401
|
+
POST: withCors(getPostRoute(options), allowedOrigins),
|
|
402
|
+
PUT: withCors(getPutRoute(options), allowedOrigins),
|
|
403
|
+
DELETE: withCors(getDeleteRoute(options), allowedOrigins),
|
|
404
|
+
...allowedOrigins?.length ? {
|
|
405
|
+
OPTIONS: (req) => {
|
|
406
|
+
const corsHeaders = getCorsHeaders(
|
|
407
|
+
req.headers.get("origin"),
|
|
408
|
+
allowedOrigins
|
|
409
|
+
);
|
|
410
|
+
return new import_server4.NextResponse(null, {
|
|
411
|
+
status: 204,
|
|
412
|
+
headers: corsHeaders ?? void 0
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
} : {}
|
|
375
416
|
};
|
|
376
417
|
}
|
|
377
418
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
2
|
import { InitRoutesOptions } from './types.mjs';
|
|
3
3
|
export { default as AuthFetch } from './server.mjs';
|
|
4
4
|
export { checkAuthStatus } from './token.mjs';
|
|
@@ -48,13 +48,14 @@ import '../../graphql/types.mjs';
|
|
|
48
48
|
* @category Auth
|
|
49
49
|
*/
|
|
50
50
|
declare function getEmailAuthRoutes(options: InitRoutesOptions): {
|
|
51
|
-
|
|
51
|
+
OPTIONS?: ((req: NextRequest) => NextResponse<unknown>) | undefined;
|
|
52
|
+
GET: (req: NextRequest) => Promise<NextResponse<{
|
|
52
53
|
accessToken: string | undefined;
|
|
53
54
|
refreshToken: string | undefined;
|
|
54
55
|
}>>;
|
|
55
|
-
POST: (req:
|
|
56
|
-
PUT: (req:
|
|
57
|
-
DELETE: (req:
|
|
56
|
+
POST: (req: NextRequest) => Promise<NextResponse<unknown> | undefined>;
|
|
57
|
+
PUT: (req: NextRequest) => Promise<NextResponse<unknown> | undefined>;
|
|
58
|
+
DELETE: (req: NextRequest) => Promise<NextResponse<{
|
|
58
59
|
accessToken: string | undefined;
|
|
59
60
|
refreshToken: string | undefined;
|
|
60
61
|
}>>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
2
|
import { InitRoutesOptions } from './types.js';
|
|
3
3
|
export { default as AuthFetch } from './server.js';
|
|
4
4
|
export { checkAuthStatus } from './token.js';
|
|
@@ -48,13 +48,14 @@ import '../../graphql/types.js';
|
|
|
48
48
|
* @category Auth
|
|
49
49
|
*/
|
|
50
50
|
declare function getEmailAuthRoutes(options: InitRoutesOptions): {
|
|
51
|
-
|
|
51
|
+
OPTIONS?: ((req: NextRequest) => NextResponse<unknown>) | undefined;
|
|
52
|
+
GET: (req: NextRequest) => Promise<NextResponse<{
|
|
52
53
|
accessToken: string | undefined;
|
|
53
54
|
refreshToken: string | undefined;
|
|
54
55
|
}>>;
|
|
55
|
-
POST: (req:
|
|
56
|
-
PUT: (req:
|
|
57
|
-
DELETE: (req:
|
|
56
|
+
POST: (req: NextRequest) => Promise<NextResponse<unknown> | undefined>;
|
|
57
|
+
PUT: (req: NextRequest) => Promise<NextResponse<unknown> | undefined>;
|
|
58
|
+
DELETE: (req: NextRequest) => Promise<NextResponse<{
|
|
58
59
|
accessToken: string | undefined;
|
|
59
60
|
refreshToken: string | undefined;
|
|
60
61
|
}>>;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// src/auth/email/index.ts
|
|
2
|
+
import { NextResponse as NextResponse3 } from "next/server";
|
|
3
|
+
|
|
1
4
|
// src/auth/email/token.ts
|
|
2
5
|
import { compare } from "bcryptjs";
|
|
3
6
|
import { JsonWebTokenError, sign, verify } from "jsonwebtoken";
|
|
@@ -331,12 +334,52 @@ function AuthFetch() {
|
|
|
331
334
|
}
|
|
332
335
|
|
|
333
336
|
// src/auth/email/index.ts
|
|
337
|
+
function getCorsHeaders(origin, allowedOrigins) {
|
|
338
|
+
if (!origin || !allowedOrigins.includes(origin)) return null;
|
|
339
|
+
return {
|
|
340
|
+
"Access-Control-Allow-Origin": origin,
|
|
341
|
+
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
|
|
342
|
+
"Access-Control-Allow-Headers": "Content-Type, Authorization",
|
|
343
|
+
"Access-Control-Allow-Credentials": "true"
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
function withCors(handler, allowedOrigins) {
|
|
347
|
+
if (!allowedOrigins?.length) return handler;
|
|
348
|
+
return ((req) => {
|
|
349
|
+
return handler(req).then((response) => {
|
|
350
|
+
if (!response) return response;
|
|
351
|
+
const corsHeaders = getCorsHeaders(
|
|
352
|
+
req.headers.get("origin"),
|
|
353
|
+
allowedOrigins
|
|
354
|
+
);
|
|
355
|
+
if (corsHeaders) {
|
|
356
|
+
Object.entries(corsHeaders).forEach(([key, value]) => {
|
|
357
|
+
response.headers.set(key, value);
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
return response;
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
}
|
|
334
364
|
function getEmailAuthRoutes(options) {
|
|
365
|
+
const { allowedOrigins } = options;
|
|
335
366
|
return {
|
|
336
|
-
GET: getGetRoute(options),
|
|
337
|
-
POST: getPostRoute(options),
|
|
338
|
-
PUT: getPutRoute(options),
|
|
339
|
-
DELETE: getDeleteRoute(options)
|
|
367
|
+
GET: withCors(getGetRoute(options), allowedOrigins),
|
|
368
|
+
POST: withCors(getPostRoute(options), allowedOrigins),
|
|
369
|
+
PUT: withCors(getPutRoute(options), allowedOrigins),
|
|
370
|
+
DELETE: withCors(getDeleteRoute(options), allowedOrigins),
|
|
371
|
+
...allowedOrigins?.length ? {
|
|
372
|
+
OPTIONS: (req) => {
|
|
373
|
+
const corsHeaders = getCorsHeaders(
|
|
374
|
+
req.headers.get("origin"),
|
|
375
|
+
allowedOrigins
|
|
376
|
+
);
|
|
377
|
+
return new NextResponse3(null, {
|
|
378
|
+
status: 204,
|
|
379
|
+
headers: corsHeaders ?? void 0
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
} : {}
|
|
340
383
|
};
|
|
341
384
|
}
|
|
342
385
|
export {
|
|
@@ -31,6 +31,7 @@ type InitRoutesOptions = {
|
|
|
31
31
|
onLogin?: (userId: number | null, body: any) => Promise<void>;
|
|
32
32
|
onRefresh?: (userId: number | null, body: any) => Promise<void>;
|
|
33
33
|
onLogout?: (userId: number | null, body: any) => Promise<void>;
|
|
34
|
+
allowedOrigins?: string[];
|
|
34
35
|
};
|
|
35
36
|
|
|
36
37
|
export type { InitRoutesOptions };
|
|
@@ -31,6 +31,7 @@ type InitRoutesOptions = {
|
|
|
31
31
|
onLogin?: (userId: number | null, body: any) => Promise<void>;
|
|
32
32
|
onRefresh?: (userId: number | null, body: any) => Promise<void>;
|
|
33
33
|
onLogout?: (userId: number | null, body: any) => Promise<void>;
|
|
34
|
+
allowedOrigins?: string[];
|
|
34
35
|
};
|
|
35
36
|
|
|
36
37
|
export type { InitRoutesOptions };
|
package/dist/auth/index.cjs.js
CHANGED
|
@@ -41,6 +41,9 @@ __export(auth_exports, {
|
|
|
41
41
|
});
|
|
42
42
|
module.exports = __toCommonJS(auth_exports);
|
|
43
43
|
|
|
44
|
+
// src/auth/email/index.ts
|
|
45
|
+
var import_server4 = require("next/server");
|
|
46
|
+
|
|
44
47
|
// src/auth/email/token.ts
|
|
45
48
|
var import_bcryptjs = require("bcryptjs");
|
|
46
49
|
var import_jsonwebtoken = require("jsonwebtoken");
|
|
@@ -382,18 +385,58 @@ function AuthFetch() {
|
|
|
382
385
|
}
|
|
383
386
|
|
|
384
387
|
// src/auth/email/index.ts
|
|
388
|
+
function getCorsHeaders(origin, allowedOrigins) {
|
|
389
|
+
if (!origin || !allowedOrigins.includes(origin)) return null;
|
|
390
|
+
return {
|
|
391
|
+
"Access-Control-Allow-Origin": origin,
|
|
392
|
+
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
|
|
393
|
+
"Access-Control-Allow-Headers": "Content-Type, Authorization",
|
|
394
|
+
"Access-Control-Allow-Credentials": "true"
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
function withCors(handler, allowedOrigins) {
|
|
398
|
+
if (!allowedOrigins?.length) return handler;
|
|
399
|
+
return ((req) => {
|
|
400
|
+
return handler(req).then((response) => {
|
|
401
|
+
if (!response) return response;
|
|
402
|
+
const corsHeaders = getCorsHeaders(
|
|
403
|
+
req.headers.get("origin"),
|
|
404
|
+
allowedOrigins
|
|
405
|
+
);
|
|
406
|
+
if (corsHeaders) {
|
|
407
|
+
Object.entries(corsHeaders).forEach(([key, value]) => {
|
|
408
|
+
response.headers.set(key, value);
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
return response;
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
}
|
|
385
415
|
function getEmailAuthRoutes(options) {
|
|
416
|
+
const { allowedOrigins } = options;
|
|
386
417
|
return {
|
|
387
|
-
GET: getGetRoute(options),
|
|
388
|
-
POST: getPostRoute(options),
|
|
389
|
-
PUT: getPutRoute(options),
|
|
390
|
-
DELETE: getDeleteRoute(options)
|
|
418
|
+
GET: withCors(getGetRoute(options), allowedOrigins),
|
|
419
|
+
POST: withCors(getPostRoute(options), allowedOrigins),
|
|
420
|
+
PUT: withCors(getPutRoute(options), allowedOrigins),
|
|
421
|
+
DELETE: withCors(getDeleteRoute(options), allowedOrigins),
|
|
422
|
+
...allowedOrigins?.length ? {
|
|
423
|
+
OPTIONS: (req) => {
|
|
424
|
+
const corsHeaders = getCorsHeaders(
|
|
425
|
+
req.headers.get("origin"),
|
|
426
|
+
allowedOrigins
|
|
427
|
+
);
|
|
428
|
+
return new import_server4.NextResponse(null, {
|
|
429
|
+
status: 204,
|
|
430
|
+
headers: corsHeaders ?? void 0
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
} : {}
|
|
391
434
|
};
|
|
392
435
|
}
|
|
393
436
|
|
|
394
437
|
// src/auth/google/get.ts
|
|
395
438
|
var import_googleapis = require("googleapis");
|
|
396
|
-
var
|
|
439
|
+
var import_server6 = require("next/server");
|
|
397
440
|
var import_uuid = require("uuid");
|
|
398
441
|
var getGoogleGetRoute = ({
|
|
399
442
|
getUserIdFromEmail,
|
|
@@ -423,7 +466,7 @@ var getGoogleGetRoute = ({
|
|
|
423
466
|
prompt: "consent",
|
|
424
467
|
redirect_uri: url
|
|
425
468
|
});
|
|
426
|
-
const res =
|
|
469
|
+
const res = import_server6.NextResponse.redirect(authorizationUrl);
|
|
427
470
|
res.cookies.set("state", state2, {
|
|
428
471
|
httpOnly: true,
|
|
429
472
|
secure: true
|
|
@@ -432,12 +475,12 @@ var getGoogleGetRoute = ({
|
|
|
432
475
|
}
|
|
433
476
|
const errorURL = errorRedirectURL || redirectURL;
|
|
434
477
|
if (error) {
|
|
435
|
-
return
|
|
478
|
+
return import_server6.NextResponse.redirect(errorURL);
|
|
436
479
|
}
|
|
437
480
|
const state = req.nextUrl.searchParams.get("state") || void 0;
|
|
438
481
|
if (code && state) {
|
|
439
482
|
const localState = req.cookies.get("state")?.value;
|
|
440
|
-
if (localState !== state) return
|
|
483
|
+
if (localState !== state) return import_server6.NextResponse.redirect(errorURL);
|
|
441
484
|
const { tokens } = await oauth2Client.getToken(code);
|
|
442
485
|
oauth2Client.setCredentials(tokens);
|
|
443
486
|
const userInfoRequest = await import_googleapis.google.oauth2({
|
|
@@ -449,7 +492,7 @@ var getGoogleGetRoute = ({
|
|
|
449
492
|
const { data } = JSON.parse(localState);
|
|
450
493
|
const id = await getUserIdFromEmail(user, data);
|
|
451
494
|
if (id) {
|
|
452
|
-
const res =
|
|
495
|
+
const res = import_server6.NextResponse.redirect(redirectURL);
|
|
453
496
|
res.cookies.set(
|
|
454
497
|
REFRESH_COOKIE_NAME,
|
|
455
498
|
generateRefreshToken(id, getEnv("REFRESH_KEY" /* REFRESH_KEY */)),
|
|
@@ -467,7 +510,7 @@ var getGoogleGetRoute = ({
|
|
|
467
510
|
}
|
|
468
511
|
}
|
|
469
512
|
}
|
|
470
|
-
return
|
|
513
|
+
return import_server6.NextResponse.redirect(errorURL);
|
|
471
514
|
};
|
|
472
515
|
};
|
|
473
516
|
|
|
@@ -479,7 +522,7 @@ function initGoogleAuth(props) {
|
|
|
479
522
|
}
|
|
480
523
|
|
|
481
524
|
// src/auth/instagram/route.ts
|
|
482
|
-
var
|
|
525
|
+
var import_server8 = require("next/server");
|
|
483
526
|
|
|
484
527
|
// src/auth/instagram/utils.ts
|
|
485
528
|
async function getRefreshedInstagramAccessToken(token) {
|
|
@@ -541,7 +584,7 @@ var getInstagramUser = (token, id, fields) => {
|
|
|
541
584
|
};
|
|
542
585
|
|
|
543
586
|
// src/socials/meta-webhook.ts
|
|
544
|
-
var
|
|
587
|
+
var import_server7 = require("next/server");
|
|
545
588
|
|
|
546
589
|
// src/auth/instagram/route.ts
|
|
547
590
|
var getInstagramRoute = ({
|
|
@@ -549,7 +592,7 @@ var getInstagramRoute = ({
|
|
|
549
592
|
errorRedirectURL,
|
|
550
593
|
onUser
|
|
551
594
|
}) => {
|
|
552
|
-
const handleError2 = (message) =>
|
|
595
|
+
const handleError2 = (message) => import_server8.NextResponse.redirect(`${errorRedirectURL}?error=${message}`);
|
|
553
596
|
return async (req) => {
|
|
554
597
|
const accessCode = req.nextUrl.searchParams.get("code");
|
|
555
598
|
const error = req.nextUrl.searchParams.get("error");
|
|
@@ -573,7 +616,7 @@ var getInstagramRoute = ({
|
|
|
573
616
|
instagramData.accessToken
|
|
574
617
|
);
|
|
575
618
|
if (errorMessage) return handleError2(errorMessage);
|
|
576
|
-
return
|
|
619
|
+
return import_server8.NextResponse.redirect(redirectURL);
|
|
577
620
|
};
|
|
578
621
|
};
|
|
579
622
|
|
package/dist/auth/index.esm.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// src/auth/email/index.ts
|
|
2
|
+
import { NextResponse as NextResponse3 } from "next/server";
|
|
3
|
+
|
|
1
4
|
// src/auth/email/token.ts
|
|
2
5
|
import { compare } from "bcryptjs";
|
|
3
6
|
import { JsonWebTokenError, sign, verify } from "jsonwebtoken";
|
|
@@ -343,18 +346,58 @@ function AuthFetch() {
|
|
|
343
346
|
}
|
|
344
347
|
|
|
345
348
|
// src/auth/email/index.ts
|
|
349
|
+
function getCorsHeaders(origin, allowedOrigins) {
|
|
350
|
+
if (!origin || !allowedOrigins.includes(origin)) return null;
|
|
351
|
+
return {
|
|
352
|
+
"Access-Control-Allow-Origin": origin,
|
|
353
|
+
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
|
|
354
|
+
"Access-Control-Allow-Headers": "Content-Type, Authorization",
|
|
355
|
+
"Access-Control-Allow-Credentials": "true"
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
function withCors(handler, allowedOrigins) {
|
|
359
|
+
if (!allowedOrigins?.length) return handler;
|
|
360
|
+
return ((req) => {
|
|
361
|
+
return handler(req).then((response) => {
|
|
362
|
+
if (!response) return response;
|
|
363
|
+
const corsHeaders = getCorsHeaders(
|
|
364
|
+
req.headers.get("origin"),
|
|
365
|
+
allowedOrigins
|
|
366
|
+
);
|
|
367
|
+
if (corsHeaders) {
|
|
368
|
+
Object.entries(corsHeaders).forEach(([key, value]) => {
|
|
369
|
+
response.headers.set(key, value);
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
return response;
|
|
373
|
+
});
|
|
374
|
+
});
|
|
375
|
+
}
|
|
346
376
|
function getEmailAuthRoutes(options) {
|
|
377
|
+
const { allowedOrigins } = options;
|
|
347
378
|
return {
|
|
348
|
-
GET: getGetRoute(options),
|
|
349
|
-
POST: getPostRoute(options),
|
|
350
|
-
PUT: getPutRoute(options),
|
|
351
|
-
DELETE: getDeleteRoute(options)
|
|
379
|
+
GET: withCors(getGetRoute(options), allowedOrigins),
|
|
380
|
+
POST: withCors(getPostRoute(options), allowedOrigins),
|
|
381
|
+
PUT: withCors(getPutRoute(options), allowedOrigins),
|
|
382
|
+
DELETE: withCors(getDeleteRoute(options), allowedOrigins),
|
|
383
|
+
...allowedOrigins?.length ? {
|
|
384
|
+
OPTIONS: (req) => {
|
|
385
|
+
const corsHeaders = getCorsHeaders(
|
|
386
|
+
req.headers.get("origin"),
|
|
387
|
+
allowedOrigins
|
|
388
|
+
);
|
|
389
|
+
return new NextResponse3(null, {
|
|
390
|
+
status: 204,
|
|
391
|
+
headers: corsHeaders ?? void 0
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
} : {}
|
|
352
395
|
};
|
|
353
396
|
}
|
|
354
397
|
|
|
355
398
|
// src/auth/google/get.ts
|
|
356
399
|
import { google } from "googleapis";
|
|
357
|
-
import { NextResponse as
|
|
400
|
+
import { NextResponse as NextResponse4 } from "next/server";
|
|
358
401
|
import { v4 } from "uuid";
|
|
359
402
|
var getGoogleGetRoute = ({
|
|
360
403
|
getUserIdFromEmail,
|
|
@@ -384,7 +427,7 @@ var getGoogleGetRoute = ({
|
|
|
384
427
|
prompt: "consent",
|
|
385
428
|
redirect_uri: url
|
|
386
429
|
});
|
|
387
|
-
const res =
|
|
430
|
+
const res = NextResponse4.redirect(authorizationUrl);
|
|
388
431
|
res.cookies.set("state", state2, {
|
|
389
432
|
httpOnly: true,
|
|
390
433
|
secure: true
|
|
@@ -393,12 +436,12 @@ var getGoogleGetRoute = ({
|
|
|
393
436
|
}
|
|
394
437
|
const errorURL = errorRedirectURL || redirectURL;
|
|
395
438
|
if (error) {
|
|
396
|
-
return
|
|
439
|
+
return NextResponse4.redirect(errorURL);
|
|
397
440
|
}
|
|
398
441
|
const state = req.nextUrl.searchParams.get("state") || void 0;
|
|
399
442
|
if (code && state) {
|
|
400
443
|
const localState = req.cookies.get("state")?.value;
|
|
401
|
-
if (localState !== state) return
|
|
444
|
+
if (localState !== state) return NextResponse4.redirect(errorURL);
|
|
402
445
|
const { tokens } = await oauth2Client.getToken(code);
|
|
403
446
|
oauth2Client.setCredentials(tokens);
|
|
404
447
|
const userInfoRequest = await google.oauth2({
|
|
@@ -410,7 +453,7 @@ var getGoogleGetRoute = ({
|
|
|
410
453
|
const { data } = JSON.parse(localState);
|
|
411
454
|
const id = await getUserIdFromEmail(user, data);
|
|
412
455
|
if (id) {
|
|
413
|
-
const res =
|
|
456
|
+
const res = NextResponse4.redirect(redirectURL);
|
|
414
457
|
res.cookies.set(
|
|
415
458
|
REFRESH_COOKIE_NAME,
|
|
416
459
|
generateRefreshToken(id, getEnv("REFRESH_KEY" /* REFRESH_KEY */)),
|
|
@@ -428,7 +471,7 @@ var getGoogleGetRoute = ({
|
|
|
428
471
|
}
|
|
429
472
|
}
|
|
430
473
|
}
|
|
431
|
-
return
|
|
474
|
+
return NextResponse4.redirect(errorURL);
|
|
432
475
|
};
|
|
433
476
|
};
|
|
434
477
|
|
|
@@ -440,7 +483,7 @@ function initGoogleAuth(props) {
|
|
|
440
483
|
}
|
|
441
484
|
|
|
442
485
|
// src/auth/instagram/route.ts
|
|
443
|
-
import { NextResponse as
|
|
486
|
+
import { NextResponse as NextResponse6 } from "next/server";
|
|
444
487
|
|
|
445
488
|
// src/auth/instagram/utils.ts
|
|
446
489
|
async function getRefreshedInstagramAccessToken(token) {
|
|
@@ -502,7 +545,7 @@ var getInstagramUser = (token, id, fields) => {
|
|
|
502
545
|
};
|
|
503
546
|
|
|
504
547
|
// src/socials/meta-webhook.ts
|
|
505
|
-
import { NextResponse as
|
|
548
|
+
import { NextResponse as NextResponse5 } from "next/server";
|
|
506
549
|
|
|
507
550
|
// src/auth/instagram/route.ts
|
|
508
551
|
var getInstagramRoute = ({
|
|
@@ -510,7 +553,7 @@ var getInstagramRoute = ({
|
|
|
510
553
|
errorRedirectURL,
|
|
511
554
|
onUser
|
|
512
555
|
}) => {
|
|
513
|
-
const handleError2 = (message) =>
|
|
556
|
+
const handleError2 = (message) => NextResponse6.redirect(`${errorRedirectURL}?error=${message}`);
|
|
514
557
|
return async (req) => {
|
|
515
558
|
const accessCode = req.nextUrl.searchParams.get("code");
|
|
516
559
|
const error = req.nextUrl.searchParams.get("error");
|
|
@@ -534,7 +577,7 @@ var getInstagramRoute = ({
|
|
|
534
577
|
instagramData.accessToken
|
|
535
578
|
);
|
|
536
579
|
if (errorMessage) return handleError2(errorMessage);
|
|
537
|
-
return
|
|
580
|
+
return NextResponse6.redirect(redirectURL);
|
|
538
581
|
};
|
|
539
582
|
};
|
|
540
583
|
|