naystack 1.1.11 → 1.1.12-beta.1
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 +203 -0
- package/dist/auth/email/index.d.mts +18 -0
- package/dist/auth/email/index.d.ts +18 -0
- package/dist/auth/email/index.esm.js +176 -0
- package/dist/auth/email/routes/delete.cjs.js +58 -0
- package/dist/auth/email/routes/delete.d.mts +8 -0
- package/dist/auth/email/routes/delete.d.ts +8 -0
- package/dist/auth/email/routes/delete.esm.js +31 -0
- package/dist/auth/email/routes/get.cjs.js +83 -0
- package/dist/auth/email/routes/get.d.mts +11 -0
- package/dist/auth/email/routes/get.d.ts +11 -0
- package/dist/auth/email/routes/get.esm.js +56 -0
- package/dist/auth/email/routes/post.cjs.js +149 -0
- package/dist/auth/email/routes/post.d.mts +8 -0
- package/dist/auth/email/routes/post.d.ts +8 -0
- package/dist/auth/email/routes/post.esm.js +124 -0
- package/dist/auth/email/routes/put.cjs.js +135 -0
- package/dist/auth/email/routes/put.d.mts +8 -0
- package/dist/auth/email/routes/put.d.ts +8 -0
- package/dist/auth/email/routes/put.esm.js +108 -0
- package/dist/auth/email/token.cjs.js +85 -0
- package/dist/auth/email/token.d.mts +13 -0
- package/dist/auth/email/token.d.ts +13 -0
- package/dist/auth/email/token.esm.js +56 -0
- package/dist/auth/email/types.cjs.js +18 -0
- package/dist/auth/email/types.d.mts +14 -0
- package/dist/auth/email/types.d.ts +14 -0
- package/dist/auth/email/types.esm.js +0 -0
- package/dist/auth/email/utils.cjs.js +83 -0
- package/dist/auth/email/utils.d.mts +16 -0
- package/dist/auth/email/utils.d.ts +16 -0
- package/dist/auth/email/utils.esm.js +55 -0
- package/dist/auth/index.d.mts +4 -45
- package/dist/auth/index.d.ts +4 -45
- package/dist/auth/types.cjs.js +18 -0
- package/dist/auth/types.d.mts +21 -0
- package/dist/auth/types.d.ts +21 -0
- package/dist/auth/types.esm.js +0 -0
- package/dist/auth/utils/errors.cjs.js +35 -0
- package/dist/auth/utils/errors.d.mts +6 -0
- package/dist/auth/utils/errors.d.ts +6 -0
- package/dist/auth/utils/errors.esm.js +10 -0
- package/dist/graphql/context.cjs.js +76 -0
- package/dist/graphql/context.d.mts +6 -0
- package/dist/graphql/context.d.ts +6 -0
- package/dist/graphql/context.esm.js +51 -0
- package/dist/graphql/index.d.mts +7 -23
- package/dist/graphql/index.d.ts +7 -23
- package/dist/graphql/init.cjs.js +124 -0
- package/dist/graphql/init.d.mts +16 -0
- package/dist/graphql/init.d.ts +16 -0
- package/dist/graphql/init.esm.js +104 -0
- package/dist/graphql/types.cjs.js +18 -0
- package/dist/graphql/types.d.mts +8 -0
- package/dist/graphql/types.d.ts +8 -0
- package/dist/graphql/types.esm.js +0 -0
- package/dist/graphql/utils.cjs.js +134 -0
- package/dist/graphql/utils.d.mts +29 -0
- package/dist/graphql/utils.d.ts +29 -0
- package/dist/graphql/utils.esm.js +118 -0
- package/dist/socials/index.d.mts +9 -130
- package/dist/socials/index.d.ts +9 -130
- package/dist/socials/instagram/getters.cjs.js +119 -0
- package/dist/socials/instagram/getters.d.mts +39 -0
- package/dist/socials/instagram/getters.d.ts +39 -0
- package/dist/socials/instagram/getters.esm.js +86 -0
- package/dist/socials/instagram/setters.cjs.js +54 -0
- package/dist/socials/instagram/setters.d.mts +8 -0
- package/dist/socials/instagram/setters.d.ts +8 -0
- package/dist/socials/instagram/setters.esm.js +27 -0
- package/dist/socials/instagram/types.cjs.js +18 -0
- package/dist/socials/instagram/types.d.mts +57 -0
- package/dist/socials/instagram/types.d.ts +57 -0
- package/dist/socials/instagram/types.esm.js +0 -0
- package/dist/socials/instagram/utils.cjs.js +44 -0
- package/dist/socials/instagram/utils.d.mts +6 -0
- package/dist/socials/instagram/utils.d.ts +6 -0
- package/dist/socials/instagram/utils.esm.js +18 -0
- package/dist/socials/instagram/webhook.cjs.js +57 -0
- package/dist/socials/instagram/webhook.d.mts +12 -0
- package/dist/socials/instagram/webhook.d.ts +12 -0
- package/dist/socials/instagram/webhook.esm.js +30 -0
- package/dist/socials/meta-webhook.cjs.js +36 -0
- package/dist/socials/meta-webhook.d.mts +5 -0
- package/dist/socials/meta-webhook.d.ts +5 -0
- package/dist/socials/meta-webhook.esm.js +11 -0
- package/dist/socials/threads/getters.cjs.js +60 -0
- package/dist/socials/threads/getters.d.mts +7 -0
- package/dist/socials/threads/getters.d.ts +7 -0
- package/dist/socials/threads/getters.esm.js +31 -0
- package/dist/socials/threads/setters.cjs.js +87 -0
- package/dist/socials/threads/setters.d.mts +6 -0
- package/dist/socials/threads/setters.d.ts +6 -0
- package/dist/socials/threads/setters.esm.js +57 -0
- package/dist/socials/threads/types.cjs.js +18 -0
- package/dist/socials/threads/types.d.mts +7 -0
- package/dist/socials/threads/types.d.ts +7 -0
- package/dist/socials/threads/types.esm.js +0 -0
- package/dist/socials/threads/utils.cjs.js +39 -0
- package/dist/socials/threads/utils.d.mts +4 -0
- package/dist/socials/threads/utils.d.ts +4 -0
- package/dist/socials/threads/utils.esm.js +13 -0
- package/dist/socials/threads/webhook.cjs.js +54 -0
- package/dist/socials/threads/webhook.d.mts +12 -0
- package/dist/socials/threads/webhook.d.ts +12 -0
- package/dist/socials/threads/webhook.esm.js +27 -0
- package/package.json +1 -1
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// src/auth/email/token.ts
|
|
2
|
+
import { compare } from "bcryptjs";
|
|
3
|
+
import { JsonWebTokenError, sign, verify } from "jsonwebtoken";
|
|
4
|
+
import { NextResponse } from "next/server";
|
|
5
|
+
function generateAccessToken(id, signingKey) {
|
|
6
|
+
return sign({ id }, signingKey, {
|
|
7
|
+
expiresIn: "2h"
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
function generateRefreshToken(id, refreshKey) {
|
|
11
|
+
return sign({ id }, refreshKey);
|
|
12
|
+
}
|
|
13
|
+
function getTokenizedResponse(accessToken, refreshToken) {
|
|
14
|
+
const body = { accessToken, refreshToken };
|
|
15
|
+
const response = NextResponse.json(body, {
|
|
16
|
+
status: 200
|
|
17
|
+
});
|
|
18
|
+
if (!accessToken) {
|
|
19
|
+
response.cookies.set("refresh", "", {
|
|
20
|
+
secure: false,
|
|
21
|
+
httpOnly: true,
|
|
22
|
+
expires: 0
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
if (refreshToken !== void 0) {
|
|
26
|
+
response.cookies.set("refresh", refreshToken, {
|
|
27
|
+
secure: false,
|
|
28
|
+
httpOnly: true,
|
|
29
|
+
expires: refreshToken === "" ? 0 : new Date(Date.now() + 60 * 60 * 24 * 365 * 1e3)
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return response;
|
|
33
|
+
}
|
|
34
|
+
function getUserIdFromRefreshToken(refreshKey, refreshToken) {
|
|
35
|
+
if (refreshToken)
|
|
36
|
+
try {
|
|
37
|
+
const decoded = verify(refreshToken, refreshKey);
|
|
38
|
+
if (typeof decoded !== "string" && typeof decoded.id === "number")
|
|
39
|
+
return decoded.id;
|
|
40
|
+
} catch (e) {
|
|
41
|
+
if (!(e instanceof JsonWebTokenError)) console.error(e, "errors");
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
function verifyUser(user, password) {
|
|
47
|
+
if (!user.password) return false;
|
|
48
|
+
return compare(password, user.password);
|
|
49
|
+
}
|
|
50
|
+
export {
|
|
51
|
+
generateAccessToken,
|
|
52
|
+
generateRefreshToken,
|
|
53
|
+
getTokenizedResponse,
|
|
54
|
+
getUserIdFromRefreshToken,
|
|
55
|
+
verifyUser
|
|
56
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/auth/email/types.ts
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { UserOutput, UserInput, ErrorHandler } from '../types.mjs';
|
|
2
|
+
import 'next/server';
|
|
3
|
+
|
|
4
|
+
type InitRoutesOptions = {
|
|
5
|
+
getUser: (email: string) => Promise<UserOutput | undefined>;
|
|
6
|
+
createUser: (user: UserInput) => Promise<UserOutput | undefined>;
|
|
7
|
+
onError?: ErrorHandler;
|
|
8
|
+
signingKey: string;
|
|
9
|
+
refreshKey: string;
|
|
10
|
+
turnstileKey?: string;
|
|
11
|
+
onSignUp: (user: UserOutput) => void;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type { InitRoutesOptions };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { UserOutput, UserInput, ErrorHandler } from '../types.js';
|
|
2
|
+
import 'next/server';
|
|
3
|
+
|
|
4
|
+
type InitRoutesOptions = {
|
|
5
|
+
getUser: (email: string) => Promise<UserOutput | undefined>;
|
|
6
|
+
createUser: (user: UserInput) => Promise<UserOutput | undefined>;
|
|
7
|
+
onError?: ErrorHandler;
|
|
8
|
+
signingKey: string;
|
|
9
|
+
refreshKey: string;
|
|
10
|
+
turnstileKey?: string;
|
|
11
|
+
onSignUp: (user: UserOutput) => void;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type { InitRoutesOptions };
|
|
File without changes
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/auth/email/utils.ts
|
|
21
|
+
var utils_exports = {};
|
|
22
|
+
__export(utils_exports, {
|
|
23
|
+
massageRequest: () => massageRequest,
|
|
24
|
+
verifyCaptcha: () => verifyCaptcha
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(utils_exports);
|
|
27
|
+
|
|
28
|
+
// src/auth/utils/errors.ts
|
|
29
|
+
var import_server = require("next/server");
|
|
30
|
+
function handleError(status, message, onError) {
|
|
31
|
+
const res = onError?.({ status, message });
|
|
32
|
+
if (res) return res;
|
|
33
|
+
return new import_server.NextResponse(message, { status });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// src/auth/email/utils.ts
|
|
37
|
+
async function massageRequest(req, options) {
|
|
38
|
+
const data = await req.json();
|
|
39
|
+
if (!data.email || !data.password)
|
|
40
|
+
return {
|
|
41
|
+
error: handleError(400, "Missing email or password", options.onError)
|
|
42
|
+
};
|
|
43
|
+
if (options.turnstileKey) {
|
|
44
|
+
if (!data.captchaToken)
|
|
45
|
+
return { error: handleError(400, "Missing captcha", options.onError) };
|
|
46
|
+
if (!await verifyCaptcha(data.captchaToken, options.turnstileKey))
|
|
47
|
+
return {
|
|
48
|
+
error: handleError(400, "Invalid captcha", options.onError)
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
data: {
|
|
53
|
+
email: data.email,
|
|
54
|
+
password: data.password,
|
|
55
|
+
...data
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
async function verifyCaptcha(token, secret) {
|
|
60
|
+
const res = await fetch(
|
|
61
|
+
"https://challenges.cloudflare.com/turnstile/v0/siteverify",
|
|
62
|
+
{
|
|
63
|
+
method: "POST",
|
|
64
|
+
headers: {
|
|
65
|
+
"Content-Type": "application/json"
|
|
66
|
+
},
|
|
67
|
+
body: JSON.stringify({
|
|
68
|
+
secret,
|
|
69
|
+
response: token
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
if (res.ok) {
|
|
74
|
+
const data = await res.json();
|
|
75
|
+
return data.success;
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
80
|
+
0 && (module.exports = {
|
|
81
|
+
massageRequest,
|
|
82
|
+
verifyCaptcha
|
|
83
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { InitRoutesOptions } from './types.mjs';
|
|
3
|
+
import '../types.mjs';
|
|
4
|
+
|
|
5
|
+
declare function massageRequest(req: NextRequest, options: InitRoutesOptions): Promise<{
|
|
6
|
+
error?: NextResponse;
|
|
7
|
+
data?: {
|
|
8
|
+
email: string;
|
|
9
|
+
password: string;
|
|
10
|
+
} & {
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
};
|
|
13
|
+
}>;
|
|
14
|
+
declare function verifyCaptcha(token: string, secret?: string): Promise<boolean>;
|
|
15
|
+
|
|
16
|
+
export { massageRequest, verifyCaptcha };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { InitRoutesOptions } from './types.js';
|
|
3
|
+
import '../types.js';
|
|
4
|
+
|
|
5
|
+
declare function massageRequest(req: NextRequest, options: InitRoutesOptions): Promise<{
|
|
6
|
+
error?: NextResponse;
|
|
7
|
+
data?: {
|
|
8
|
+
email: string;
|
|
9
|
+
password: string;
|
|
10
|
+
} & {
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
};
|
|
13
|
+
}>;
|
|
14
|
+
declare function verifyCaptcha(token: string, secret?: string): Promise<boolean>;
|
|
15
|
+
|
|
16
|
+
export { massageRequest, verifyCaptcha };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// src/auth/utils/errors.ts
|
|
2
|
+
import { NextResponse } from "next/server";
|
|
3
|
+
function handleError(status, message, onError) {
|
|
4
|
+
const res = onError?.({ status, message });
|
|
5
|
+
if (res) return res;
|
|
6
|
+
return new NextResponse(message, { status });
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// src/auth/email/utils.ts
|
|
10
|
+
async function massageRequest(req, options) {
|
|
11
|
+
const data = await req.json();
|
|
12
|
+
if (!data.email || !data.password)
|
|
13
|
+
return {
|
|
14
|
+
error: handleError(400, "Missing email or password", options.onError)
|
|
15
|
+
};
|
|
16
|
+
if (options.turnstileKey) {
|
|
17
|
+
if (!data.captchaToken)
|
|
18
|
+
return { error: handleError(400, "Missing captcha", options.onError) };
|
|
19
|
+
if (!await verifyCaptcha(data.captchaToken, options.turnstileKey))
|
|
20
|
+
return {
|
|
21
|
+
error: handleError(400, "Invalid captcha", options.onError)
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
data: {
|
|
26
|
+
email: data.email,
|
|
27
|
+
password: data.password,
|
|
28
|
+
...data
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
async function verifyCaptcha(token, secret) {
|
|
33
|
+
const res = await fetch(
|
|
34
|
+
"https://challenges.cloudflare.com/turnstile/v0/siteverify",
|
|
35
|
+
{
|
|
36
|
+
method: "POST",
|
|
37
|
+
headers: {
|
|
38
|
+
"Content-Type": "application/json"
|
|
39
|
+
},
|
|
40
|
+
body: JSON.stringify({
|
|
41
|
+
secret,
|
|
42
|
+
response: token
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
if (res.ok) {
|
|
47
|
+
const data = await res.json();
|
|
48
|
+
return data.success;
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
massageRequest,
|
|
54
|
+
verifyCaptcha
|
|
55
|
+
};
|
package/dist/auth/index.d.mts
CHANGED
|
@@ -1,45 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
status: number;
|
|
6
|
-
message: string;
|
|
7
|
-
}) => NextResponse;
|
|
8
|
-
type UserInput = {
|
|
9
|
-
email: string;
|
|
10
|
-
password: string;
|
|
11
|
-
} & {
|
|
12
|
-
[key: string]: unknown;
|
|
13
|
-
};
|
|
14
|
-
type UserOutput = {
|
|
15
|
-
id: number;
|
|
16
|
-
email: string;
|
|
17
|
-
password: string | null;
|
|
18
|
-
} & {
|
|
19
|
-
[key: string]: unknown;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
type InitRoutesOptions = {
|
|
23
|
-
getUser: (email: string) => Promise<UserOutput | undefined>;
|
|
24
|
-
createUser: (user: UserInput) => Promise<UserOutput | undefined>;
|
|
25
|
-
onError?: ErrorHandler;
|
|
26
|
-
signingKey: string;
|
|
27
|
-
refreshKey: string;
|
|
28
|
-
turnstileKey?: string;
|
|
29
|
-
onSignUp: (user: UserOutput) => void;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
declare function getEmailAuthRoutes(options: InitRoutesOptions): {
|
|
33
|
-
GET: (req: next_server.NextRequest) => next_server.NextResponse<{
|
|
34
|
-
accessToken: string | undefined;
|
|
35
|
-
refreshToken: string | undefined;
|
|
36
|
-
}>;
|
|
37
|
-
POST: (req: next_server.NextRequest) => Promise<next_server.NextResponse<unknown> | undefined>;
|
|
38
|
-
PUT: (req: next_server.NextRequest) => Promise<next_server.NextResponse<unknown> | undefined>;
|
|
39
|
-
DELETE: () => next_server.NextResponse<{
|
|
40
|
-
accessToken: string | undefined;
|
|
41
|
-
refreshToken: string | undefined;
|
|
42
|
-
}>;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export { getEmailAuthRoutes };
|
|
1
|
+
export { getEmailAuthRoutes } from './email/index.mjs';
|
|
2
|
+
import 'next/server';
|
|
3
|
+
import './email/types.mjs';
|
|
4
|
+
import './types.mjs';
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,45 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
status: number;
|
|
6
|
-
message: string;
|
|
7
|
-
}) => NextResponse;
|
|
8
|
-
type UserInput = {
|
|
9
|
-
email: string;
|
|
10
|
-
password: string;
|
|
11
|
-
} & {
|
|
12
|
-
[key: string]: unknown;
|
|
13
|
-
};
|
|
14
|
-
type UserOutput = {
|
|
15
|
-
id: number;
|
|
16
|
-
email: string;
|
|
17
|
-
password: string | null;
|
|
18
|
-
} & {
|
|
19
|
-
[key: string]: unknown;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
type InitRoutesOptions = {
|
|
23
|
-
getUser: (email: string) => Promise<UserOutput | undefined>;
|
|
24
|
-
createUser: (user: UserInput) => Promise<UserOutput | undefined>;
|
|
25
|
-
onError?: ErrorHandler;
|
|
26
|
-
signingKey: string;
|
|
27
|
-
refreshKey: string;
|
|
28
|
-
turnstileKey?: string;
|
|
29
|
-
onSignUp: (user: UserOutput) => void;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
declare function getEmailAuthRoutes(options: InitRoutesOptions): {
|
|
33
|
-
GET: (req: next_server.NextRequest) => next_server.NextResponse<{
|
|
34
|
-
accessToken: string | undefined;
|
|
35
|
-
refreshToken: string | undefined;
|
|
36
|
-
}>;
|
|
37
|
-
POST: (req: next_server.NextRequest) => Promise<next_server.NextResponse<unknown> | undefined>;
|
|
38
|
-
PUT: (req: next_server.NextRequest) => Promise<next_server.NextResponse<unknown> | undefined>;
|
|
39
|
-
DELETE: () => next_server.NextResponse<{
|
|
40
|
-
accessToken: string | undefined;
|
|
41
|
-
refreshToken: string | undefined;
|
|
42
|
-
}>;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export { getEmailAuthRoutes };
|
|
1
|
+
export { getEmailAuthRoutes } from './email/index.js';
|
|
2
|
+
import 'next/server';
|
|
3
|
+
import './email/types.js';
|
|
4
|
+
import './types.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/auth/types.ts
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server';
|
|
2
|
+
|
|
3
|
+
type ErrorHandler = (error: {
|
|
4
|
+
status: number;
|
|
5
|
+
message: string;
|
|
6
|
+
}) => NextResponse;
|
|
7
|
+
type UserInput = {
|
|
8
|
+
email: string;
|
|
9
|
+
password: string;
|
|
10
|
+
} & {
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
};
|
|
13
|
+
type UserOutput = {
|
|
14
|
+
id: number;
|
|
15
|
+
email: string;
|
|
16
|
+
password: string | null;
|
|
17
|
+
} & {
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type { ErrorHandler, UserInput, UserOutput };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server';
|
|
2
|
+
|
|
3
|
+
type ErrorHandler = (error: {
|
|
4
|
+
status: number;
|
|
5
|
+
message: string;
|
|
6
|
+
}) => NextResponse;
|
|
7
|
+
type UserInput = {
|
|
8
|
+
email: string;
|
|
9
|
+
password: string;
|
|
10
|
+
} & {
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
};
|
|
13
|
+
type UserOutput = {
|
|
14
|
+
id: number;
|
|
15
|
+
email: string;
|
|
16
|
+
password: string | null;
|
|
17
|
+
} & {
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type { ErrorHandler, UserInput, UserOutput };
|
|
File without changes
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/auth/utils/errors.ts
|
|
21
|
+
var errors_exports = {};
|
|
22
|
+
__export(errors_exports, {
|
|
23
|
+
handleError: () => handleError
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(errors_exports);
|
|
26
|
+
var import_server = require("next/server");
|
|
27
|
+
function handleError(status, message, onError) {
|
|
28
|
+
const res = onError?.({ status, message });
|
|
29
|
+
if (res) return res;
|
|
30
|
+
return new import_server.NextResponse(message, { status });
|
|
31
|
+
}
|
|
32
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
+
0 && (module.exports = {
|
|
34
|
+
handleError
|
|
35
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/auth/utils/errors.ts
|
|
2
|
+
import { NextResponse } from "next/server";
|
|
3
|
+
function handleError(status, message, onError) {
|
|
4
|
+
const res = onError?.({ status, message });
|
|
5
|
+
if (res) return res;
|
|
6
|
+
return new NextResponse(message, { status });
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
handleError
|
|
10
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/graphql/context.ts
|
|
21
|
+
var context_exports = {};
|
|
22
|
+
__export(context_exports, {
|
|
23
|
+
getContext: () => getContext
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(context_exports);
|
|
26
|
+
var import_jsonwebtoken2 = require("jsonwebtoken");
|
|
27
|
+
|
|
28
|
+
// src/auth/email/token.ts
|
|
29
|
+
var import_bcryptjs = require("bcryptjs");
|
|
30
|
+
var import_jsonwebtoken = require("jsonwebtoken");
|
|
31
|
+
var import_server = require("next/server");
|
|
32
|
+
function getUserIdFromRefreshToken(refreshKey, refreshToken) {
|
|
33
|
+
if (refreshToken)
|
|
34
|
+
try {
|
|
35
|
+
const decoded = (0, import_jsonwebtoken.verify)(refreshToken, refreshKey);
|
|
36
|
+
if (typeof decoded !== "string" && typeof decoded.id === "number")
|
|
37
|
+
return decoded.id;
|
|
38
|
+
} catch (e) {
|
|
39
|
+
if (!(e instanceof import_jsonwebtoken.JsonWebTokenError)) console.error(e, "errors");
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/auth/utils/errors.ts
|
|
46
|
+
var import_server2 = require("next/server");
|
|
47
|
+
function handleError(status, message, onError) {
|
|
48
|
+
const res = onError?.({ status, message });
|
|
49
|
+
if (res) return res;
|
|
50
|
+
return new import_server2.NextResponse(message, { status });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/graphql/context.ts
|
|
54
|
+
var getContext = (refreshKey, signingKey) => async (req) => {
|
|
55
|
+
const bearer = req.headers.get("authorization");
|
|
56
|
+
const isMobile = req.headers.get("x-platform-is-mobile");
|
|
57
|
+
if (!bearer) {
|
|
58
|
+
if (isMobile) return { userId: null };
|
|
59
|
+
const refresh = req.cookies.get("refresh")?.value;
|
|
60
|
+
const userId = getUserIdFromRefreshToken(refreshKey, refresh);
|
|
61
|
+
if (userId) return { userId, onlyQuery: true };
|
|
62
|
+
return { userId: null };
|
|
63
|
+
}
|
|
64
|
+
const token = bearer.slice(7);
|
|
65
|
+
try {
|
|
66
|
+
const res = (0, import_jsonwebtoken2.verify)(token, signingKey);
|
|
67
|
+
return { userId: typeof res !== "string" ? res.id : null };
|
|
68
|
+
} catch {
|
|
69
|
+
if (isMobile) return handleError(401, "Refresh token is invalid.");
|
|
70
|
+
}
|
|
71
|
+
return { userId: null };
|
|
72
|
+
};
|
|
73
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
74
|
+
0 && (module.exports = {
|
|
75
|
+
getContext
|
|
76
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// src/graphql/context.ts
|
|
2
|
+
import { verify as verify2 } from "jsonwebtoken";
|
|
3
|
+
|
|
4
|
+
// src/auth/email/token.ts
|
|
5
|
+
import { compare } from "bcryptjs";
|
|
6
|
+
import { JsonWebTokenError, sign, verify } from "jsonwebtoken";
|
|
7
|
+
import { NextResponse } from "next/server";
|
|
8
|
+
function getUserIdFromRefreshToken(refreshKey, refreshToken) {
|
|
9
|
+
if (refreshToken)
|
|
10
|
+
try {
|
|
11
|
+
const decoded = verify(refreshToken, refreshKey);
|
|
12
|
+
if (typeof decoded !== "string" && typeof decoded.id === "number")
|
|
13
|
+
return decoded.id;
|
|
14
|
+
} catch (e) {
|
|
15
|
+
if (!(e instanceof JsonWebTokenError)) console.error(e, "errors");
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// src/auth/utils/errors.ts
|
|
22
|
+
import { NextResponse as NextResponse2 } from "next/server";
|
|
23
|
+
function handleError(status, message, onError) {
|
|
24
|
+
const res = onError?.({ status, message });
|
|
25
|
+
if (res) return res;
|
|
26
|
+
return new NextResponse2(message, { status });
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// src/graphql/context.ts
|
|
30
|
+
var getContext = (refreshKey, signingKey) => async (req) => {
|
|
31
|
+
const bearer = req.headers.get("authorization");
|
|
32
|
+
const isMobile = req.headers.get("x-platform-is-mobile");
|
|
33
|
+
if (!bearer) {
|
|
34
|
+
if (isMobile) return { userId: null };
|
|
35
|
+
const refresh = req.cookies.get("refresh")?.value;
|
|
36
|
+
const userId = getUserIdFromRefreshToken(refreshKey, refresh);
|
|
37
|
+
if (userId) return { userId, onlyQuery: true };
|
|
38
|
+
return { userId: null };
|
|
39
|
+
}
|
|
40
|
+
const token = bearer.slice(7);
|
|
41
|
+
try {
|
|
42
|
+
const res = verify2(token, signingKey);
|
|
43
|
+
return { userId: typeof res !== "string" ? res.id : null };
|
|
44
|
+
} catch {
|
|
45
|
+
if (isMobile) return handleError(401, "Refresh token is invalid.");
|
|
46
|
+
}
|
|
47
|
+
return { userId: null };
|
|
48
|
+
};
|
|
49
|
+
export {
|
|
50
|
+
getContext
|
|
51
|
+
};
|