tinacms-authjs 0.0.0-fd664d8-20250407054012 → 0.0.0-fd7d6a8-20251202025028
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/index.js +26 -60
- package/dist/tinacms.js +2855 -2857
- package/package.json +7 -7
- package/dist/tinacms.mjs +0 -3126
package/dist/index.js
CHANGED
|
@@ -1,54 +1,24 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
|
|
29
1
|
// src/index.ts
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
TinaAuthJSOptions: () => TinaAuthJSOptions,
|
|
34
|
-
TinaCredentialsProvider: () => TinaCredentialsProvider
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(index_exports);
|
|
37
|
-
var import_next_auth = __toESM(require("next-auth"));
|
|
38
|
-
var import_credentials = __toESM(require("next-auth/providers/credentials"));
|
|
39
|
-
var import_next = require("next-auth/next");
|
|
2
|
+
import NextAuth from "next-auth";
|
|
3
|
+
import CredentialsProvider from "next-auth/providers/credentials";
|
|
4
|
+
import { getServerSession } from "next-auth/next";
|
|
40
5
|
|
|
41
6
|
// src/tinacms.ts
|
|
42
|
-
|
|
43
|
-
|
|
7
|
+
import {
|
|
8
|
+
getCsrfToken,
|
|
9
|
+
getSession,
|
|
10
|
+
signIn,
|
|
11
|
+
signOut,
|
|
12
|
+
SessionProvider
|
|
13
|
+
} from "next-auth/react";
|
|
14
|
+
import { AbstractAuthProvider } from "tinacms";
|
|
44
15
|
var TINA_CREDENTIALS_PROVIDER_NAME = "TinaCredentials";
|
|
45
16
|
|
|
46
17
|
// src/index.ts
|
|
47
18
|
var authenticate = async (databaseClient, username, password) => {
|
|
48
|
-
var _a;
|
|
49
19
|
try {
|
|
50
20
|
const result = await databaseClient.authenticate({ username, password });
|
|
51
|
-
return
|
|
21
|
+
return result.data?.authenticate || null;
|
|
52
22
|
} catch (e) {
|
|
53
23
|
console.error(e);
|
|
54
24
|
}
|
|
@@ -64,17 +34,16 @@ var TinaAuthJSOptions = ({
|
|
|
64
34
|
}) => ({
|
|
65
35
|
callbacks: {
|
|
66
36
|
jwt: async ({ token: jwt, account }) => {
|
|
67
|
-
var _a, _b, _c, _d;
|
|
68
37
|
if (account) {
|
|
69
38
|
if (debug) {
|
|
70
39
|
console.table(jwt);
|
|
71
40
|
}
|
|
72
41
|
try {
|
|
73
|
-
if (jwt
|
|
42
|
+
if (jwt?.[uidProp]) {
|
|
74
43
|
const sub = jwt[uidProp];
|
|
75
44
|
const result = await databaseClient.authorize({ sub });
|
|
76
|
-
jwt.role = !!
|
|
77
|
-
jwt.passwordChangeRequired =
|
|
45
|
+
jwt.role = !!result.data?.authorize ? "user" : "guest";
|
|
46
|
+
jwt.passwordChangeRequired = result.data?.authorize?._password?.passwordChangeRequired || false;
|
|
78
47
|
} else if (debug) {
|
|
79
48
|
console.log(`jwt missing specified uidProp: ${uidProp}`);
|
|
80
49
|
}
|
|
@@ -103,7 +72,7 @@ var TinaCredentialsProvider = ({
|
|
|
103
72
|
databaseClient,
|
|
104
73
|
name = TINA_CREDENTIALS_PROVIDER_NAME
|
|
105
74
|
}) => {
|
|
106
|
-
const p = (
|
|
75
|
+
const p = CredentialsProvider({
|
|
107
76
|
credentials: {
|
|
108
77
|
username: { label: "Username", type: "text" },
|
|
109
78
|
password: { label: "Password", type: "password" }
|
|
@@ -118,33 +87,32 @@ var AuthJsBackendAuthProvider = ({
|
|
|
118
87
|
}) => {
|
|
119
88
|
const authProvider = {
|
|
120
89
|
initialize: async () => {
|
|
121
|
-
|
|
122
|
-
if (!((_a = authOptions.providers) == null ? void 0 : _a.length)) {
|
|
90
|
+
if (!authOptions.providers?.length) {
|
|
123
91
|
throw new Error("No auth providers specified");
|
|
124
92
|
}
|
|
125
93
|
const [provider, ...rest] = authOptions.providers;
|
|
126
94
|
if (rest.length > 0 || provider.type !== "credentials" || provider.name !== TINA_CREDENTIALS_PROVIDER_NAME) {
|
|
127
95
|
console.warn(
|
|
128
|
-
`WARNING: Catch-all api route ['/api/tina/*'] with specified Auth.js provider ['${provider.name}'] not supported. See https://tina.io/docs/self-
|
|
96
|
+
`WARNING: Catch-all api route ['/api/tina/*'] with specified Auth.js provider ['${provider.name}'] not supported. See https://tina.io/docs/r/self-hosting-overview for more information.`
|
|
129
97
|
);
|
|
130
98
|
}
|
|
131
99
|
},
|
|
132
100
|
isAuthorized: async (req, res) => {
|
|
133
|
-
const session = await
|
|
101
|
+
const session = await getServerSession(req, res, authOptions);
|
|
134
102
|
if (!req.session) {
|
|
135
103
|
Object.defineProperty(req, "session", {
|
|
136
104
|
value: session,
|
|
137
105
|
writable: false
|
|
138
106
|
});
|
|
139
107
|
}
|
|
140
|
-
if (!
|
|
108
|
+
if (!session?.user) {
|
|
141
109
|
return {
|
|
142
110
|
errorCode: 401,
|
|
143
111
|
errorMessage: "Unauthorized",
|
|
144
112
|
isAuthorized: false
|
|
145
113
|
};
|
|
146
114
|
}
|
|
147
|
-
if ((session
|
|
115
|
+
if ((session?.user).role !== "user") {
|
|
148
116
|
return {
|
|
149
117
|
errorCode: 403,
|
|
150
118
|
errorMessage: "Forbidden",
|
|
@@ -157,23 +125,21 @@ var AuthJsBackendAuthProvider = ({
|
|
|
157
125
|
auth: {
|
|
158
126
|
secure: false,
|
|
159
127
|
handler: async (req, res, opts) => {
|
|
160
|
-
var _a, _b, _c;
|
|
161
128
|
const url = new URL(
|
|
162
129
|
req.url,
|
|
163
|
-
`http://${
|
|
130
|
+
`http://${req.headers?.host || "localhost"}`
|
|
164
131
|
);
|
|
165
|
-
const authSubRoutes =
|
|
132
|
+
const authSubRoutes = url.pathname?.replace(`${opts.basePath}auth/`, "")?.split("/");
|
|
166
133
|
req.query.nextauth = authSubRoutes;
|
|
167
|
-
await (
|
|
134
|
+
await NextAuth(authOptions)(req, res);
|
|
168
135
|
}
|
|
169
136
|
}
|
|
170
137
|
}
|
|
171
138
|
};
|
|
172
139
|
return authProvider;
|
|
173
140
|
};
|
|
174
|
-
|
|
175
|
-
0 && (module.exports = {
|
|
141
|
+
export {
|
|
176
142
|
AuthJsBackendAuthProvider,
|
|
177
143
|
TinaAuthJSOptions,
|
|
178
144
|
TinaCredentialsProvider
|
|
179
|
-
}
|
|
145
|
+
};
|