tinacms-authjs 0.0.0-fbcd928-20241024223724 → 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.d.ts +1 -1
- package/dist/index.js +26 -57
- 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,50 +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
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
-
mod
|
|
22
|
-
));
|
|
23
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
-
|
|
25
1
|
// src/index.ts
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
TinaAuthJSOptions: () => TinaAuthJSOptions,
|
|
30
|
-
TinaCredentialsProvider: () => TinaCredentialsProvider
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(src_exports);
|
|
33
|
-
var import_next_auth = __toESM(require("next-auth"));
|
|
34
|
-
var import_credentials = __toESM(require("next-auth/providers/credentials"));
|
|
35
|
-
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";
|
|
36
5
|
|
|
37
6
|
// src/tinacms.ts
|
|
38
|
-
|
|
39
|
-
|
|
7
|
+
import {
|
|
8
|
+
getCsrfToken,
|
|
9
|
+
getSession,
|
|
10
|
+
signIn,
|
|
11
|
+
signOut,
|
|
12
|
+
SessionProvider
|
|
13
|
+
} from "next-auth/react";
|
|
14
|
+
import { AbstractAuthProvider } from "tinacms";
|
|
40
15
|
var TINA_CREDENTIALS_PROVIDER_NAME = "TinaCredentials";
|
|
41
16
|
|
|
42
17
|
// src/index.ts
|
|
43
18
|
var authenticate = async (databaseClient, username, password) => {
|
|
44
|
-
var _a;
|
|
45
19
|
try {
|
|
46
20
|
const result = await databaseClient.authenticate({ username, password });
|
|
47
|
-
return
|
|
21
|
+
return result.data?.authenticate || null;
|
|
48
22
|
} catch (e) {
|
|
49
23
|
console.error(e);
|
|
50
24
|
}
|
|
@@ -60,17 +34,16 @@ var TinaAuthJSOptions = ({
|
|
|
60
34
|
}) => ({
|
|
61
35
|
callbacks: {
|
|
62
36
|
jwt: async ({ token: jwt, account }) => {
|
|
63
|
-
var _a, _b, _c, _d;
|
|
64
37
|
if (account) {
|
|
65
38
|
if (debug) {
|
|
66
39
|
console.table(jwt);
|
|
67
40
|
}
|
|
68
41
|
try {
|
|
69
|
-
if (jwt
|
|
42
|
+
if (jwt?.[uidProp]) {
|
|
70
43
|
const sub = jwt[uidProp];
|
|
71
44
|
const result = await databaseClient.authorize({ sub });
|
|
72
|
-
jwt.role = !!
|
|
73
|
-
jwt.passwordChangeRequired =
|
|
45
|
+
jwt.role = !!result.data?.authorize ? "user" : "guest";
|
|
46
|
+
jwt.passwordChangeRequired = result.data?.authorize?._password?.passwordChangeRequired || false;
|
|
74
47
|
} else if (debug) {
|
|
75
48
|
console.log(`jwt missing specified uidProp: ${uidProp}`);
|
|
76
49
|
}
|
|
@@ -84,7 +57,6 @@ var TinaAuthJSOptions = ({
|
|
|
84
57
|
return jwt;
|
|
85
58
|
},
|
|
86
59
|
session: async ({ session, token: jwt }) => {
|
|
87
|
-
;
|
|
88
60
|
session.user.role = jwt.role;
|
|
89
61
|
session.user.passwordChangeRequired = jwt.passwordChangeRequired;
|
|
90
62
|
session.user[uidProp] = jwt[uidProp];
|
|
@@ -100,7 +72,7 @@ var TinaCredentialsProvider = ({
|
|
|
100
72
|
databaseClient,
|
|
101
73
|
name = TINA_CREDENTIALS_PROVIDER_NAME
|
|
102
74
|
}) => {
|
|
103
|
-
const p = (
|
|
75
|
+
const p = CredentialsProvider({
|
|
104
76
|
credentials: {
|
|
105
77
|
username: { label: "Username", type: "text" },
|
|
106
78
|
password: { label: "Password", type: "password" }
|
|
@@ -115,33 +87,32 @@ var AuthJsBackendAuthProvider = ({
|
|
|
115
87
|
}) => {
|
|
116
88
|
const authProvider = {
|
|
117
89
|
initialize: async () => {
|
|
118
|
-
|
|
119
|
-
if (!((_a = authOptions.providers) == null ? void 0 : _a.length)) {
|
|
90
|
+
if (!authOptions.providers?.length) {
|
|
120
91
|
throw new Error("No auth providers specified");
|
|
121
92
|
}
|
|
122
93
|
const [provider, ...rest] = authOptions.providers;
|
|
123
94
|
if (rest.length > 0 || provider.type !== "credentials" || provider.name !== TINA_CREDENTIALS_PROVIDER_NAME) {
|
|
124
95
|
console.warn(
|
|
125
|
-
`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.`
|
|
126
97
|
);
|
|
127
98
|
}
|
|
128
99
|
},
|
|
129
100
|
isAuthorized: async (req, res) => {
|
|
130
|
-
const session = await
|
|
101
|
+
const session = await getServerSession(req, res, authOptions);
|
|
131
102
|
if (!req.session) {
|
|
132
103
|
Object.defineProperty(req, "session", {
|
|
133
104
|
value: session,
|
|
134
105
|
writable: false
|
|
135
106
|
});
|
|
136
107
|
}
|
|
137
|
-
if (!
|
|
108
|
+
if (!session?.user) {
|
|
138
109
|
return {
|
|
139
110
|
errorCode: 401,
|
|
140
111
|
errorMessage: "Unauthorized",
|
|
141
112
|
isAuthorized: false
|
|
142
113
|
};
|
|
143
114
|
}
|
|
144
|
-
if ((session
|
|
115
|
+
if ((session?.user).role !== "user") {
|
|
145
116
|
return {
|
|
146
117
|
errorCode: 403,
|
|
147
118
|
errorMessage: "Forbidden",
|
|
@@ -154,23 +125,21 @@ var AuthJsBackendAuthProvider = ({
|
|
|
154
125
|
auth: {
|
|
155
126
|
secure: false,
|
|
156
127
|
handler: async (req, res, opts) => {
|
|
157
|
-
var _a, _b, _c;
|
|
158
128
|
const url = new URL(
|
|
159
129
|
req.url,
|
|
160
|
-
`http://${
|
|
130
|
+
`http://${req.headers?.host || "localhost"}`
|
|
161
131
|
);
|
|
162
|
-
const authSubRoutes =
|
|
132
|
+
const authSubRoutes = url.pathname?.replace(`${opts.basePath}auth/`, "")?.split("/");
|
|
163
133
|
req.query.nextauth = authSubRoutes;
|
|
164
|
-
await (
|
|
134
|
+
await NextAuth(authOptions)(req, res);
|
|
165
135
|
}
|
|
166
136
|
}
|
|
167
137
|
}
|
|
168
138
|
};
|
|
169
139
|
return authProvider;
|
|
170
140
|
};
|
|
171
|
-
|
|
172
|
-
0 && (module.exports = {
|
|
141
|
+
export {
|
|
173
142
|
AuthJsBackendAuthProvider,
|
|
174
143
|
TinaAuthJSOptions,
|
|
175
144
|
TinaCredentialsProvider
|
|
176
|
-
}
|
|
145
|
+
};
|