tinacms-authjs 0.0.0-cef656e-20250119001929 → 0.0.0-cf37070-20251203063307
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.d.ts +1 -1
- package/dist/index.js +26 -61
- package/dist/tinacms.js +2855 -2857
- package/package.json +8 -8
- package/dist/tinacms.mjs +0 -3126
package/dist/index.d.ts
CHANGED
|
@@ -24,4 +24,4 @@ declare const TinaCredentialsProvider: ({ databaseClient, name, }: {
|
|
|
24
24
|
declare const AuthJsBackendAuthProvider: ({ authOptions, }: {
|
|
25
25
|
authOptions: AuthOptions;
|
|
26
26
|
}) => BackendAuthProvider;
|
|
27
|
-
export { TinaCredentialsProvider, TinaAuthJSOptions, AuthJsBackendAuthProvider };
|
|
27
|
+
export { TinaCredentialsProvider, TinaAuthJSOptions, AuthJsBackendAuthProvider, };
|
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(src_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
|
}
|
|
@@ -88,7 +57,6 @@ var TinaAuthJSOptions = ({
|
|
|
88
57
|
return jwt;
|
|
89
58
|
},
|
|
90
59
|
session: async ({ session, token: jwt }) => {
|
|
91
|
-
;
|
|
92
60
|
session.user.role = jwt.role;
|
|
93
61
|
session.user.passwordChangeRequired = jwt.passwordChangeRequired;
|
|
94
62
|
session.user[uidProp] = jwt[uidProp];
|
|
@@ -104,7 +72,7 @@ var TinaCredentialsProvider = ({
|
|
|
104
72
|
databaseClient,
|
|
105
73
|
name = TINA_CREDENTIALS_PROVIDER_NAME
|
|
106
74
|
}) => {
|
|
107
|
-
const p = (
|
|
75
|
+
const p = CredentialsProvider({
|
|
108
76
|
credentials: {
|
|
109
77
|
username: { label: "Username", type: "text" },
|
|
110
78
|
password: { label: "Password", type: "password" }
|
|
@@ -119,33 +87,32 @@ var AuthJsBackendAuthProvider = ({
|
|
|
119
87
|
}) => {
|
|
120
88
|
const authProvider = {
|
|
121
89
|
initialize: async () => {
|
|
122
|
-
|
|
123
|
-
if (!((_a = authOptions.providers) == null ? void 0 : _a.length)) {
|
|
90
|
+
if (!authOptions.providers?.length) {
|
|
124
91
|
throw new Error("No auth providers specified");
|
|
125
92
|
}
|
|
126
93
|
const [provider, ...rest] = authOptions.providers;
|
|
127
94
|
if (rest.length > 0 || provider.type !== "credentials" || provider.name !== TINA_CREDENTIALS_PROVIDER_NAME) {
|
|
128
95
|
console.warn(
|
|
129
|
-
`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.`
|
|
130
97
|
);
|
|
131
98
|
}
|
|
132
99
|
},
|
|
133
100
|
isAuthorized: async (req, res) => {
|
|
134
|
-
const session = await
|
|
101
|
+
const session = await getServerSession(req, res, authOptions);
|
|
135
102
|
if (!req.session) {
|
|
136
103
|
Object.defineProperty(req, "session", {
|
|
137
104
|
value: session,
|
|
138
105
|
writable: false
|
|
139
106
|
});
|
|
140
107
|
}
|
|
141
|
-
if (!
|
|
108
|
+
if (!session?.user) {
|
|
142
109
|
return {
|
|
143
110
|
errorCode: 401,
|
|
144
111
|
errorMessage: "Unauthorized",
|
|
145
112
|
isAuthorized: false
|
|
146
113
|
};
|
|
147
114
|
}
|
|
148
|
-
if ((session
|
|
115
|
+
if ((session?.user).role !== "user") {
|
|
149
116
|
return {
|
|
150
117
|
errorCode: 403,
|
|
151
118
|
errorMessage: "Forbidden",
|
|
@@ -158,23 +125,21 @@ var AuthJsBackendAuthProvider = ({
|
|
|
158
125
|
auth: {
|
|
159
126
|
secure: false,
|
|
160
127
|
handler: async (req, res, opts) => {
|
|
161
|
-
var _a, _b, _c;
|
|
162
128
|
const url = new URL(
|
|
163
129
|
req.url,
|
|
164
|
-
`http://${
|
|
130
|
+
`http://${req.headers?.host || "localhost"}`
|
|
165
131
|
);
|
|
166
|
-
const authSubRoutes =
|
|
132
|
+
const authSubRoutes = url.pathname?.replace(`${opts.basePath}auth/`, "")?.split("/");
|
|
167
133
|
req.query.nextauth = authSubRoutes;
|
|
168
|
-
await (
|
|
134
|
+
await NextAuth(authOptions)(req, res);
|
|
169
135
|
}
|
|
170
136
|
}
|
|
171
137
|
}
|
|
172
138
|
};
|
|
173
139
|
return authProvider;
|
|
174
140
|
};
|
|
175
|
-
|
|
176
|
-
0 && (module.exports = {
|
|
141
|
+
export {
|
|
177
142
|
AuthJsBackendAuthProvider,
|
|
178
143
|
TinaAuthJSOptions,
|
|
179
144
|
TinaCredentialsProvider
|
|
180
|
-
}
|
|
145
|
+
};
|