naystack 1.4.16 → 1.4.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/client.cjs.js +27 -12
- package/dist/auth/email/client.esm.js +27 -12
- package/dist/auth/email/index.cjs.js +32 -15
- package/dist/auth/email/index.esm.js +32 -15
- package/dist/auth/email/routes/delete.cjs.js +14 -4
- package/dist/auth/email/routes/delete.esm.js +14 -4
- package/dist/auth/email/routes/get.cjs.js +12 -2
- package/dist/auth/email/routes/get.esm.js +12 -2
- package/dist/auth/email/routes/post.cjs.js +17 -6
- package/dist/auth/email/routes/post.esm.js +17 -6
- package/dist/auth/email/routes/put.cjs.js +12 -4
- package/dist/auth/email/routes/put.esm.js +12 -4
- package/dist/auth/email/token.cjs.js +9 -2
- package/dist/auth/email/token.esm.js +9 -2
- package/dist/auth/email/types.d.mts +1 -7
- package/dist/auth/email/types.d.ts +1 -7
- package/dist/auth/email/utils.cjs.js +16 -5
- package/dist/auth/email/utils.d.mts +2 -2
- package/dist/auth/email/utils.d.ts +2 -2
- package/dist/auth/email/utils.esm.js +16 -5
- package/dist/auth/google/get.cjs.js +15 -7
- package/dist/auth/google/get.d.mts +1 -3
- package/dist/auth/google/get.d.ts +1 -3
- package/dist/auth/google/get.esm.js +15 -7
- package/dist/auth/google/index.cjs.js +15 -7
- package/dist/auth/google/index.d.mts +0 -5
- package/dist/auth/google/index.d.ts +0 -5
- package/dist/auth/google/index.esm.js +15 -7
- package/dist/auth/index.cjs.js +47 -31
- package/dist/auth/index.esm.js +47 -31
- package/dist/auth/instagram/client.cjs.js +12 -1
- package/dist/auth/instagram/client.d.mts +1 -1
- package/dist/auth/instagram/client.d.ts +1 -1
- package/dist/auth/instagram/client.esm.js +10 -1
- package/dist/auth/instagram/index.cjs.js +16 -9
- package/dist/auth/instagram/index.d.mts +0 -2
- package/dist/auth/instagram/index.d.ts +0 -2
- package/dist/auth/instagram/index.esm.js +16 -9
- package/dist/auth/instagram/route.cjs.js +16 -9
- package/dist/auth/instagram/route.d.mts +1 -1
- package/dist/auth/instagram/route.d.ts +1 -1
- package/dist/auth/instagram/route.esm.js +16 -9
- package/dist/auth/instagram/utils.cjs.js +10 -1
- package/dist/auth/instagram/utils.esm.js +8 -1
- package/dist/client/index.cjs.js +8 -1
- package/dist/client/index.esm.js +8 -1
- package/dist/client/seo.cjs.js +10 -1
- package/dist/client/seo.esm.js +8 -1
- package/dist/env.cjs.js +57 -0
- package/dist/env.d.mts +23 -0
- package/dist/env.d.ts +23 -0
- package/dist/env.esm.js +31 -0
- package/dist/file/client.cjs.js +10 -1
- package/dist/file/client.esm.js +10 -1
- package/dist/file/index.cjs.js +40 -28
- package/dist/file/index.d.mts +0 -2
- package/dist/file/index.d.ts +0 -2
- package/dist/file/index.esm.js +40 -28
- package/dist/file/put.cjs.js +23 -11
- package/dist/file/put.d.mts +0 -2
- package/dist/file/put.d.ts +0 -2
- package/dist/file/put.esm.js +23 -11
- package/dist/file/setup.cjs.js +40 -28
- package/dist/file/setup.d.mts +0 -7
- package/dist/file/setup.d.ts +0 -7
- package/dist/file/setup.esm.js +40 -28
- package/dist/file/utils.cjs.js +28 -17
- package/dist/file/utils.d.mts +6 -10
- package/dist/file/utils.d.ts +6 -10
- package/dist/file/utils.esm.js +28 -17
- package/dist/graphql/client.cjs.js +15 -3
- package/dist/graphql/client.d.mts +1 -1
- package/dist/graphql/client.d.ts +1 -1
- package/dist/graphql/client.esm.js +15 -3
- package/dist/graphql/index.cjs.js +65 -3
- package/dist/graphql/index.d.mts +1 -0
- package/dist/graphql/index.d.ts +1 -0
- package/dist/graphql/index.esm.js +65 -3
- package/dist/graphql/init.cjs.js +11 -2
- package/dist/graphql/init.esm.js +11 -2
- package/dist/graphql/server.cjs.js +10 -1
- package/dist/graphql/server.esm.js +10 -1
- package/dist/graphql/utils.cjs.js +54 -1
- package/dist/graphql/utils.d.mts +10 -3
- package/dist/graphql/utils.d.ts +10 -3
- package/dist/graphql/utils.esm.js +54 -1
- package/package.json +1 -1
|
@@ -24,6 +24,13 @@ __export(put_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(put_exports);
|
|
26
26
|
|
|
27
|
+
// src/env.ts
|
|
28
|
+
function getEnv(key, skipCheck) {
|
|
29
|
+
const value = process.env[key];
|
|
30
|
+
if (!skipCheck && !value) throw new Error(`${key} is not defined`);
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
|
|
27
34
|
// src/auth/utils/errors.ts
|
|
28
35
|
var import_server = require("next/server");
|
|
29
36
|
function handleError(status, message, onError) {
|
|
@@ -85,12 +92,13 @@ async function massageRequest(req, options) {
|
|
|
85
92
|
return {
|
|
86
93
|
error: handleError(400, "Missing password", options.onError)
|
|
87
94
|
};
|
|
88
|
-
|
|
95
|
+
const turnstileKey = getEnv("TURNSTILE_KEY" /* TURNSTILE_KEY */, true);
|
|
96
|
+
if (turnstileKey) {
|
|
89
97
|
if (!data.captchaToken)
|
|
90
98
|
return {
|
|
91
99
|
error: handleError(400, "Missing captchaToken", options.onError)
|
|
92
100
|
};
|
|
93
|
-
if (!await verifyCaptcha(data.captchaToken,
|
|
101
|
+
if (!await verifyCaptcha(data.captchaToken, turnstileKey))
|
|
94
102
|
return {
|
|
95
103
|
error: handleError(400, "Invalid captcha", options.onError)
|
|
96
104
|
};
|
|
@@ -136,8 +144,8 @@ var getPutRoute = (options) => async (req) => {
|
|
|
136
144
|
await options.onLogin?.(user.id, data);
|
|
137
145
|
}
|
|
138
146
|
return getTokenizedResponse(
|
|
139
|
-
generateAccessToken(user.id,
|
|
140
|
-
generateRefreshToken(user.id,
|
|
147
|
+
generateAccessToken(user.id, getEnv("SIGNING_KEY" /* SIGNING_KEY */)),
|
|
148
|
+
generateRefreshToken(user.id, getEnv("REFRESH_KEY" /* REFRESH_KEY */))
|
|
141
149
|
);
|
|
142
150
|
}
|
|
143
151
|
return handleError(403, "Invalid password", options.onError);
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
// src/env.ts
|
|
2
|
+
function getEnv(key, skipCheck) {
|
|
3
|
+
const value = process.env[key];
|
|
4
|
+
if (!skipCheck && !value) throw new Error(`${key} is not defined`);
|
|
5
|
+
return value;
|
|
6
|
+
}
|
|
7
|
+
|
|
1
8
|
// src/auth/utils/errors.ts
|
|
2
9
|
import { NextResponse } from "next/server";
|
|
3
10
|
function handleError(status, message, onError) {
|
|
@@ -59,12 +66,13 @@ async function massageRequest(req, options) {
|
|
|
59
66
|
return {
|
|
60
67
|
error: handleError(400, "Missing password", options.onError)
|
|
61
68
|
};
|
|
62
|
-
|
|
69
|
+
const turnstileKey = getEnv("TURNSTILE_KEY" /* TURNSTILE_KEY */, true);
|
|
70
|
+
if (turnstileKey) {
|
|
63
71
|
if (!data.captchaToken)
|
|
64
72
|
return {
|
|
65
73
|
error: handleError(400, "Missing captchaToken", options.onError)
|
|
66
74
|
};
|
|
67
|
-
if (!await verifyCaptcha(data.captchaToken,
|
|
75
|
+
if (!await verifyCaptcha(data.captchaToken, turnstileKey))
|
|
68
76
|
return {
|
|
69
77
|
error: handleError(400, "Invalid captcha", options.onError)
|
|
70
78
|
};
|
|
@@ -110,8 +118,8 @@ var getPutRoute = (options) => async (req) => {
|
|
|
110
118
|
await options.onLogin?.(user.id, data);
|
|
111
119
|
}
|
|
112
120
|
return getTokenizedResponse(
|
|
113
|
-
generateAccessToken(user.id,
|
|
114
|
-
generateRefreshToken(user.id,
|
|
121
|
+
generateAccessToken(user.id, getEnv("SIGNING_KEY" /* SIGNING_KEY */)),
|
|
122
|
+
generateRefreshToken(user.id, getEnv("REFRESH_KEY" /* REFRESH_KEY */))
|
|
115
123
|
);
|
|
116
124
|
}
|
|
117
125
|
return handleError(403, "Invalid password", options.onError);
|
|
@@ -35,6 +35,13 @@ var import_headers = require("next/headers");
|
|
|
35
35
|
var import_navigation = require("next/navigation");
|
|
36
36
|
var import_server = require("next/server");
|
|
37
37
|
|
|
38
|
+
// src/env.ts
|
|
39
|
+
function getEnv(key, skipCheck) {
|
|
40
|
+
const value = process.env[key];
|
|
41
|
+
if (!skipCheck && !value) throw new Error(`${key} is not defined`);
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
|
|
38
45
|
// src/auth/constants.ts
|
|
39
46
|
var REFRESH_COOKIE_NAME = "refresh";
|
|
40
47
|
|
|
@@ -81,9 +88,9 @@ function getUserIdFromRefreshToken(refreshKey, refreshToken) {
|
|
|
81
88
|
return null;
|
|
82
89
|
}
|
|
83
90
|
function getUserIdFromAccessToken(refreshToken) {
|
|
84
|
-
if (refreshToken
|
|
91
|
+
if (refreshToken)
|
|
85
92
|
try {
|
|
86
|
-
const decoded = (0, import_jsonwebtoken.verify)(refreshToken,
|
|
93
|
+
const decoded = (0, import_jsonwebtoken.verify)(refreshToken, getEnv("SIGNING_KEY" /* SIGNING_KEY */));
|
|
87
94
|
if (typeof decoded !== "string" && typeof decoded.id === "number")
|
|
88
95
|
return decoded.id;
|
|
89
96
|
} catch (e) {
|
|
@@ -5,6 +5,13 @@ import { cookies } from "next/headers";
|
|
|
5
5
|
import { redirect } from "next/navigation";
|
|
6
6
|
import { NextResponse } from "next/server";
|
|
7
7
|
|
|
8
|
+
// src/env.ts
|
|
9
|
+
function getEnv(key, skipCheck) {
|
|
10
|
+
const value = process.env[key];
|
|
11
|
+
if (!skipCheck && !value) throw new Error(`${key} is not defined`);
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
|
|
8
15
|
// src/auth/constants.ts
|
|
9
16
|
var REFRESH_COOKIE_NAME = "refresh";
|
|
10
17
|
|
|
@@ -51,9 +58,9 @@ function getUserIdFromRefreshToken(refreshKey, refreshToken) {
|
|
|
51
58
|
return null;
|
|
52
59
|
}
|
|
53
60
|
function getUserIdFromAccessToken(refreshToken) {
|
|
54
|
-
if (refreshToken
|
|
61
|
+
if (refreshToken)
|
|
55
62
|
try {
|
|
56
|
-
const decoded = verify(refreshToken,
|
|
63
|
+
const decoded = verify(refreshToken, getEnv("SIGNING_KEY" /* SIGNING_KEY */));
|
|
57
64
|
if (typeof decoded !== "string" && typeof decoded.id === "number")
|
|
58
65
|
return decoded.id;
|
|
59
66
|
} catch (e) {
|
|
@@ -5,16 +5,10 @@ type InitRoutesOptions = {
|
|
|
5
5
|
getUser: (data: any) => Promise<UserOutput | undefined>;
|
|
6
6
|
createUser: (user: any) => Promise<UserOutput | undefined>;
|
|
7
7
|
onError?: ErrorHandler;
|
|
8
|
-
keys: AuthKeys;
|
|
9
|
-
turnstileKey?: string;
|
|
10
8
|
onSignUp?: (userId: number | null, body: any) => Promise<void>;
|
|
11
9
|
onLogin?: (userId: number | null, body: any) => Promise<void>;
|
|
12
10
|
onRefresh?: (userId: number | null, body: any) => Promise<void>;
|
|
13
11
|
onLogout?: (userId: number | null, body: any) => Promise<void>;
|
|
14
12
|
};
|
|
15
|
-
interface AuthKeys {
|
|
16
|
-
signing: string;
|
|
17
|
-
refresh: string;
|
|
18
|
-
}
|
|
19
13
|
|
|
20
|
-
export type {
|
|
14
|
+
export type { InitRoutesOptions };
|
|
@@ -5,16 +5,10 @@ type InitRoutesOptions = {
|
|
|
5
5
|
getUser: (data: any) => Promise<UserOutput | undefined>;
|
|
6
6
|
createUser: (user: any) => Promise<UserOutput | undefined>;
|
|
7
7
|
onError?: ErrorHandler;
|
|
8
|
-
keys: AuthKeys;
|
|
9
|
-
turnstileKey?: string;
|
|
10
8
|
onSignUp?: (userId: number | null, body: any) => Promise<void>;
|
|
11
9
|
onLogin?: (userId: number | null, body: any) => Promise<void>;
|
|
12
10
|
onRefresh?: (userId: number | null, body: any) => Promise<void>;
|
|
13
11
|
onLogout?: (userId: number | null, body: any) => Promise<void>;
|
|
14
12
|
};
|
|
15
|
-
interface AuthKeys {
|
|
16
|
-
signing: string;
|
|
17
|
-
refresh: string;
|
|
18
|
-
}
|
|
19
13
|
|
|
20
|
-
export type {
|
|
14
|
+
export type { InitRoutesOptions };
|
|
@@ -34,6 +34,13 @@ var import_headers = require("next/headers");
|
|
|
34
34
|
var import_navigation = require("next/navigation");
|
|
35
35
|
var import_server = require("next/server");
|
|
36
36
|
|
|
37
|
+
// src/env.ts
|
|
38
|
+
function getEnv(key, skipCheck) {
|
|
39
|
+
const value = process.env[key];
|
|
40
|
+
if (!skipCheck && !value) throw new Error(`${key} is not defined`);
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
|
|
37
44
|
// src/auth/constants.ts
|
|
38
45
|
var REFRESH_COOKIE_NAME = "refresh";
|
|
39
46
|
|
|
@@ -66,12 +73,13 @@ async function massageRequest(req, options) {
|
|
|
66
73
|
return {
|
|
67
74
|
error: handleError(400, "Missing password", options.onError)
|
|
68
75
|
};
|
|
69
|
-
|
|
76
|
+
const turnstileKey = getEnv("TURNSTILE_KEY" /* TURNSTILE_KEY */, true);
|
|
77
|
+
if (turnstileKey) {
|
|
70
78
|
if (!data.captchaToken)
|
|
71
79
|
return {
|
|
72
80
|
error: handleError(400, "Missing captchaToken", options.onError)
|
|
73
81
|
};
|
|
74
|
-
if (!await verifyCaptcha(data.captchaToken,
|
|
82
|
+
if (!await verifyCaptcha(data.captchaToken, turnstileKey))
|
|
75
83
|
return {
|
|
76
84
|
error: handleError(400, "Invalid captcha", options.onError)
|
|
77
85
|
};
|
|
@@ -104,17 +112,20 @@ async function verifyCaptcha(token, secret) {
|
|
|
104
112
|
}
|
|
105
113
|
return false;
|
|
106
114
|
}
|
|
107
|
-
var getContext = (
|
|
115
|
+
var getContext = (req) => {
|
|
108
116
|
const bearer = req.headers.get("authorization");
|
|
109
117
|
if (!bearer) {
|
|
110
118
|
const refresh = req.cookies.get(REFRESH_COOKIE_NAME)?.value;
|
|
111
|
-
const userId = getUserIdFromRefreshToken(
|
|
119
|
+
const userId = getUserIdFromRefreshToken(
|
|
120
|
+
getEnv("REFRESH_KEY" /* REFRESH_KEY */),
|
|
121
|
+
refresh
|
|
122
|
+
);
|
|
112
123
|
if (userId) return { userId, isRefreshID: true };
|
|
113
124
|
return { userId: null };
|
|
114
125
|
}
|
|
115
126
|
const token = bearer.slice(7);
|
|
116
127
|
try {
|
|
117
|
-
const res = (0, import_jsonwebtoken2.verify)(token,
|
|
128
|
+
const res = (0, import_jsonwebtoken2.verify)(token, getEnv("SIGNING_KEY" /* SIGNING_KEY */));
|
|
118
129
|
if (typeof res === "string") {
|
|
119
130
|
return { userId: null };
|
|
120
131
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
2
|
import { Context } from '../../graphql/types.mjs';
|
|
3
|
-
import { InitRoutesOptions
|
|
3
|
+
import { InitRoutesOptions } from './types.mjs';
|
|
4
4
|
import '../types.mjs';
|
|
5
5
|
|
|
6
6
|
declare function massageRequest(req: NextRequest, options: InitRoutesOptions): Promise<{
|
|
@@ -12,6 +12,6 @@ declare function massageRequest(req: NextRequest, options: InitRoutesOptions): P
|
|
|
12
12
|
};
|
|
13
13
|
}>;
|
|
14
14
|
declare function verifyCaptcha(token: string, secret?: string): Promise<boolean>;
|
|
15
|
-
declare const getContext: (
|
|
15
|
+
declare const getContext: (req: NextRequest) => Context;
|
|
16
16
|
|
|
17
17
|
export { getContext, massageRequest, verifyCaptcha };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
2
|
import { Context } from '../../graphql/types.js';
|
|
3
|
-
import { InitRoutesOptions
|
|
3
|
+
import { InitRoutesOptions } from './types.js';
|
|
4
4
|
import '../types.js';
|
|
5
5
|
|
|
6
6
|
declare function massageRequest(req: NextRequest, options: InitRoutesOptions): Promise<{
|
|
@@ -12,6 +12,6 @@ declare function massageRequest(req: NextRequest, options: InitRoutesOptions): P
|
|
|
12
12
|
};
|
|
13
13
|
}>;
|
|
14
14
|
declare function verifyCaptcha(token: string, secret?: string): Promise<boolean>;
|
|
15
|
-
declare const getContext: (
|
|
15
|
+
declare const getContext: (req: NextRequest) => Context;
|
|
16
16
|
|
|
17
17
|
export { getContext, massageRequest, verifyCaptcha };
|
|
@@ -8,6 +8,13 @@ import { cookies } from "next/headers";
|
|
|
8
8
|
import { redirect } from "next/navigation";
|
|
9
9
|
import { NextResponse } from "next/server";
|
|
10
10
|
|
|
11
|
+
// src/env.ts
|
|
12
|
+
function getEnv(key, skipCheck) {
|
|
13
|
+
const value = process.env[key];
|
|
14
|
+
if (!skipCheck && !value) throw new Error(`${key} is not defined`);
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
|
|
11
18
|
// src/auth/constants.ts
|
|
12
19
|
var REFRESH_COOKIE_NAME = "refresh";
|
|
13
20
|
|
|
@@ -40,12 +47,13 @@ async function massageRequest(req, options) {
|
|
|
40
47
|
return {
|
|
41
48
|
error: handleError(400, "Missing password", options.onError)
|
|
42
49
|
};
|
|
43
|
-
|
|
50
|
+
const turnstileKey = getEnv("TURNSTILE_KEY" /* TURNSTILE_KEY */, true);
|
|
51
|
+
if (turnstileKey) {
|
|
44
52
|
if (!data.captchaToken)
|
|
45
53
|
return {
|
|
46
54
|
error: handleError(400, "Missing captchaToken", options.onError)
|
|
47
55
|
};
|
|
48
|
-
if (!await verifyCaptcha(data.captchaToken,
|
|
56
|
+
if (!await verifyCaptcha(data.captchaToken, turnstileKey))
|
|
49
57
|
return {
|
|
50
58
|
error: handleError(400, "Invalid captcha", options.onError)
|
|
51
59
|
};
|
|
@@ -78,17 +86,20 @@ async function verifyCaptcha(token, secret) {
|
|
|
78
86
|
}
|
|
79
87
|
return false;
|
|
80
88
|
}
|
|
81
|
-
var getContext = (
|
|
89
|
+
var getContext = (req) => {
|
|
82
90
|
const bearer = req.headers.get("authorization");
|
|
83
91
|
if (!bearer) {
|
|
84
92
|
const refresh = req.cookies.get(REFRESH_COOKIE_NAME)?.value;
|
|
85
|
-
const userId = getUserIdFromRefreshToken(
|
|
93
|
+
const userId = getUserIdFromRefreshToken(
|
|
94
|
+
getEnv("REFRESH_KEY" /* REFRESH_KEY */),
|
|
95
|
+
refresh
|
|
96
|
+
);
|
|
86
97
|
if (userId) return { userId, isRefreshID: true };
|
|
87
98
|
return { userId: null };
|
|
88
99
|
}
|
|
89
100
|
const token = bearer.slice(7);
|
|
90
101
|
try {
|
|
91
|
-
const res = verify2(token,
|
|
102
|
+
const res = verify2(token, getEnv("SIGNING_KEY" /* SIGNING_KEY */));
|
|
92
103
|
if (typeof res === "string") {
|
|
93
104
|
return { userId: null };
|
|
94
105
|
}
|
|
@@ -34,6 +34,13 @@ var import_headers = require("next/headers");
|
|
|
34
34
|
var import_navigation = require("next/navigation");
|
|
35
35
|
var import_server = require("next/server");
|
|
36
36
|
|
|
37
|
+
// src/env.ts
|
|
38
|
+
function getEnv(key, skipCheck) {
|
|
39
|
+
const value = process.env[key];
|
|
40
|
+
if (!skipCheck && !value) throw new Error(`${key} is not defined`);
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
|
|
37
44
|
// src/auth/constants.ts
|
|
38
45
|
var REFRESH_COOKIE_NAME = "refresh";
|
|
39
46
|
|
|
@@ -46,13 +53,14 @@ function generateRefreshToken(id, refreshKey) {
|
|
|
46
53
|
var getGoogleGetRoute = ({
|
|
47
54
|
getUserIdFromEmail,
|
|
48
55
|
redirectURL,
|
|
49
|
-
errorRedirectURL
|
|
50
|
-
clientId,
|
|
51
|
-
clientSecret,
|
|
52
|
-
keys
|
|
56
|
+
errorRedirectURL
|
|
53
57
|
}) => {
|
|
54
|
-
const url =
|
|
55
|
-
const oauth2Client = new import_googleapis.google.auth.OAuth2(
|
|
58
|
+
const url = getEnv("NEXT_PUBLIC_GOOGLE_AUTH_ENDPOINT" /* NEXT_PUBLIC_GOOGLE_AUTH_ENDPOINT */);
|
|
59
|
+
const oauth2Client = new import_googleapis.google.auth.OAuth2(
|
|
60
|
+
getEnv("GOOGLE_CLIENT_ID" /* GOOGLE_CLIENT_ID */),
|
|
61
|
+
getEnv("GOOGLE_CLIENT_SECRET" /* GOOGLE_CLIENT_SECRET */),
|
|
62
|
+
url
|
|
63
|
+
);
|
|
56
64
|
return async (req) => {
|
|
57
65
|
const code = req.nextUrl.searchParams.get("code");
|
|
58
66
|
const error = req.nextUrl.searchParams.get("error");
|
|
@@ -96,7 +104,7 @@ var getGoogleGetRoute = ({
|
|
|
96
104
|
if (id) {
|
|
97
105
|
res.cookies.set(
|
|
98
106
|
REFRESH_COOKIE_NAME,
|
|
99
|
-
generateRefreshToken(id,
|
|
107
|
+
generateRefreshToken(id, getEnv("REFRESH_KEY" /* REFRESH_KEY */)),
|
|
100
108
|
{
|
|
101
109
|
httpOnly: true,
|
|
102
110
|
secure: true
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
2
|
import { InitGoogleAuthOptions } from './index.mjs';
|
|
3
3
|
import 'googleapis';
|
|
4
|
-
import '../email/types.mjs';
|
|
5
|
-
import '../types.mjs';
|
|
6
4
|
|
|
7
|
-
declare const getGoogleGetRoute: ({ getUserIdFromEmail, redirectURL, errorRedirectURL,
|
|
5
|
+
declare const getGoogleGetRoute: ({ getUserIdFromEmail, redirectURL, errorRedirectURL, }: InitGoogleAuthOptions) => (req: NextRequest) => Promise<NextResponse<unknown>>;
|
|
8
6
|
|
|
9
7
|
export { getGoogleGetRoute };
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
2
|
import { InitGoogleAuthOptions } from './index.js';
|
|
3
3
|
import 'googleapis';
|
|
4
|
-
import '../email/types.js';
|
|
5
|
-
import '../types.js';
|
|
6
4
|
|
|
7
|
-
declare const getGoogleGetRoute: ({ getUserIdFromEmail, redirectURL, errorRedirectURL,
|
|
5
|
+
declare const getGoogleGetRoute: ({ getUserIdFromEmail, redirectURL, errorRedirectURL, }: InitGoogleAuthOptions) => (req: NextRequest) => Promise<NextResponse<unknown>>;
|
|
8
6
|
|
|
9
7
|
export { getGoogleGetRoute };
|
|
@@ -10,6 +10,13 @@ import { cookies } from "next/headers";
|
|
|
10
10
|
import { redirect } from "next/navigation";
|
|
11
11
|
import { NextResponse } from "next/server";
|
|
12
12
|
|
|
13
|
+
// src/env.ts
|
|
14
|
+
function getEnv(key, skipCheck) {
|
|
15
|
+
const value = process.env[key];
|
|
16
|
+
if (!skipCheck && !value) throw new Error(`${key} is not defined`);
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
|
|
13
20
|
// src/auth/constants.ts
|
|
14
21
|
var REFRESH_COOKIE_NAME = "refresh";
|
|
15
22
|
|
|
@@ -22,13 +29,14 @@ function generateRefreshToken(id, refreshKey) {
|
|
|
22
29
|
var getGoogleGetRoute = ({
|
|
23
30
|
getUserIdFromEmail,
|
|
24
31
|
redirectURL,
|
|
25
|
-
errorRedirectURL
|
|
26
|
-
clientId,
|
|
27
|
-
clientSecret,
|
|
28
|
-
keys
|
|
32
|
+
errorRedirectURL
|
|
29
33
|
}) => {
|
|
30
|
-
const url =
|
|
31
|
-
const oauth2Client = new google.auth.OAuth2(
|
|
34
|
+
const url = getEnv("NEXT_PUBLIC_GOOGLE_AUTH_ENDPOINT" /* NEXT_PUBLIC_GOOGLE_AUTH_ENDPOINT */);
|
|
35
|
+
const oauth2Client = new google.auth.OAuth2(
|
|
36
|
+
getEnv("GOOGLE_CLIENT_ID" /* GOOGLE_CLIENT_ID */),
|
|
37
|
+
getEnv("GOOGLE_CLIENT_SECRET" /* GOOGLE_CLIENT_SECRET */),
|
|
38
|
+
url
|
|
39
|
+
);
|
|
32
40
|
return async (req) => {
|
|
33
41
|
const code = req.nextUrl.searchParams.get("code");
|
|
34
42
|
const error = req.nextUrl.searchParams.get("error");
|
|
@@ -72,7 +80,7 @@ var getGoogleGetRoute = ({
|
|
|
72
80
|
if (id) {
|
|
73
81
|
res.cookies.set(
|
|
74
82
|
REFRESH_COOKIE_NAME,
|
|
75
|
-
generateRefreshToken(id,
|
|
83
|
+
generateRefreshToken(id, getEnv("REFRESH_KEY" /* REFRESH_KEY */)),
|
|
76
84
|
{
|
|
77
85
|
httpOnly: true,
|
|
78
86
|
secure: true
|
|
@@ -36,6 +36,13 @@ var import_headers = require("next/headers");
|
|
|
36
36
|
var import_navigation = require("next/navigation");
|
|
37
37
|
var import_server = require("next/server");
|
|
38
38
|
|
|
39
|
+
// src/env.ts
|
|
40
|
+
function getEnv(key, skipCheck) {
|
|
41
|
+
const value = process.env[key];
|
|
42
|
+
if (!skipCheck && !value) throw new Error(`${key} is not defined`);
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
|
|
39
46
|
// src/auth/constants.ts
|
|
40
47
|
var REFRESH_COOKIE_NAME = "refresh";
|
|
41
48
|
|
|
@@ -48,13 +55,14 @@ function generateRefreshToken(id, refreshKey) {
|
|
|
48
55
|
var getGoogleGetRoute = ({
|
|
49
56
|
getUserIdFromEmail,
|
|
50
57
|
redirectURL,
|
|
51
|
-
errorRedirectURL
|
|
52
|
-
clientId,
|
|
53
|
-
clientSecret,
|
|
54
|
-
keys
|
|
58
|
+
errorRedirectURL
|
|
55
59
|
}) => {
|
|
56
|
-
const url =
|
|
57
|
-
const oauth2Client = new import_googleapis.google.auth.OAuth2(
|
|
60
|
+
const url = getEnv("NEXT_PUBLIC_GOOGLE_AUTH_ENDPOINT" /* NEXT_PUBLIC_GOOGLE_AUTH_ENDPOINT */);
|
|
61
|
+
const oauth2Client = new import_googleapis.google.auth.OAuth2(
|
|
62
|
+
getEnv("GOOGLE_CLIENT_ID" /* GOOGLE_CLIENT_ID */),
|
|
63
|
+
getEnv("GOOGLE_CLIENT_SECRET" /* GOOGLE_CLIENT_SECRET */),
|
|
64
|
+
url
|
|
65
|
+
);
|
|
58
66
|
return async (req) => {
|
|
59
67
|
const code = req.nextUrl.searchParams.get("code");
|
|
60
68
|
const error = req.nextUrl.searchParams.get("error");
|
|
@@ -98,7 +106,7 @@ var getGoogleGetRoute = ({
|
|
|
98
106
|
if (id) {
|
|
99
107
|
res.cookies.set(
|
|
100
108
|
REFRESH_COOKIE_NAME,
|
|
101
|
-
generateRefreshToken(id,
|
|
109
|
+
generateRefreshToken(id, getEnv("REFRESH_KEY" /* REFRESH_KEY */)),
|
|
102
110
|
{
|
|
103
111
|
httpOnly: true,
|
|
104
112
|
secure: true
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import * as next_server from 'next/server';
|
|
2
2
|
import { oauth2_v2 } from 'googleapis';
|
|
3
|
-
import { AuthKeys } from '../email/types.mjs';
|
|
4
|
-
import '../types.mjs';
|
|
5
3
|
|
|
6
4
|
type Schema$Userinfo = oauth2_v2.Schema$Userinfo;
|
|
7
5
|
interface InitGoogleAuthOptions {
|
|
8
6
|
getUserIdFromEmail: (email: Schema$Userinfo) => Promise<number | null>;
|
|
9
7
|
redirectURL: string;
|
|
10
8
|
errorRedirectURL?: string;
|
|
11
|
-
clientId: string;
|
|
12
|
-
clientSecret: string;
|
|
13
|
-
keys: AuthKeys;
|
|
14
9
|
}
|
|
15
10
|
declare function initGoogleAuth(props: InitGoogleAuthOptions): {
|
|
16
11
|
GET: (req: next_server.NextRequest) => Promise<next_server.NextResponse<unknown>>;
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import * as next_server from 'next/server';
|
|
2
2
|
import { oauth2_v2 } from 'googleapis';
|
|
3
|
-
import { AuthKeys } from '../email/types.js';
|
|
4
|
-
import '../types.js';
|
|
5
3
|
|
|
6
4
|
type Schema$Userinfo = oauth2_v2.Schema$Userinfo;
|
|
7
5
|
interface InitGoogleAuthOptions {
|
|
8
6
|
getUserIdFromEmail: (email: Schema$Userinfo) => Promise<number | null>;
|
|
9
7
|
redirectURL: string;
|
|
10
8
|
errorRedirectURL?: string;
|
|
11
|
-
clientId: string;
|
|
12
|
-
clientSecret: string;
|
|
13
|
-
keys: AuthKeys;
|
|
14
9
|
}
|
|
15
10
|
declare function initGoogleAuth(props: InitGoogleAuthOptions): {
|
|
16
11
|
GET: (req: next_server.NextRequest) => Promise<next_server.NextResponse<unknown>>;
|
|
@@ -10,6 +10,13 @@ import { cookies } from "next/headers";
|
|
|
10
10
|
import { redirect } from "next/navigation";
|
|
11
11
|
import { NextResponse } from "next/server";
|
|
12
12
|
|
|
13
|
+
// src/env.ts
|
|
14
|
+
function getEnv(key, skipCheck) {
|
|
15
|
+
const value = process.env[key];
|
|
16
|
+
if (!skipCheck && !value) throw new Error(`${key} is not defined`);
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
|
|
13
20
|
// src/auth/constants.ts
|
|
14
21
|
var REFRESH_COOKIE_NAME = "refresh";
|
|
15
22
|
|
|
@@ -22,13 +29,14 @@ function generateRefreshToken(id, refreshKey) {
|
|
|
22
29
|
var getGoogleGetRoute = ({
|
|
23
30
|
getUserIdFromEmail,
|
|
24
31
|
redirectURL,
|
|
25
|
-
errorRedirectURL
|
|
26
|
-
clientId,
|
|
27
|
-
clientSecret,
|
|
28
|
-
keys
|
|
32
|
+
errorRedirectURL
|
|
29
33
|
}) => {
|
|
30
|
-
const url =
|
|
31
|
-
const oauth2Client = new google.auth.OAuth2(
|
|
34
|
+
const url = getEnv("NEXT_PUBLIC_GOOGLE_AUTH_ENDPOINT" /* NEXT_PUBLIC_GOOGLE_AUTH_ENDPOINT */);
|
|
35
|
+
const oauth2Client = new google.auth.OAuth2(
|
|
36
|
+
getEnv("GOOGLE_CLIENT_ID" /* GOOGLE_CLIENT_ID */),
|
|
37
|
+
getEnv("GOOGLE_CLIENT_SECRET" /* GOOGLE_CLIENT_SECRET */),
|
|
38
|
+
url
|
|
39
|
+
);
|
|
32
40
|
return async (req) => {
|
|
33
41
|
const code = req.nextUrl.searchParams.get("code");
|
|
34
42
|
const error = req.nextUrl.searchParams.get("error");
|
|
@@ -72,7 +80,7 @@ var getGoogleGetRoute = ({
|
|
|
72
80
|
if (id) {
|
|
73
81
|
res.cookies.set(
|
|
74
82
|
REFRESH_COOKIE_NAME,
|
|
75
|
-
generateRefreshToken(id,
|
|
83
|
+
generateRefreshToken(id, getEnv("REFRESH_KEY" /* REFRESH_KEY */)),
|
|
76
84
|
{
|
|
77
85
|
httpOnly: true,
|
|
78
86
|
secure: true
|