tinacms-authjs 0.0.0-f97a9b1-20241023074747 → 0.0.0-f9fb00b-20250728042847

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 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
@@ -17,19 +17,23 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
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.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
23
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
28
 
25
29
  // src/index.ts
26
- var src_exports = {};
27
- __export(src_exports, {
30
+ var index_exports = {};
31
+ __export(index_exports, {
28
32
  AuthJsBackendAuthProvider: () => AuthJsBackendAuthProvider,
29
33
  TinaAuthJSOptions: () => TinaAuthJSOptions,
30
34
  TinaCredentialsProvider: () => TinaCredentialsProvider
31
35
  });
32
- module.exports = __toCommonJS(src_exports);
36
+ module.exports = __toCommonJS(index_exports);
33
37
  var import_next_auth = __toESM(require("next-auth"));
34
38
  var import_credentials = __toESM(require("next-auth/providers/credentials"));
35
39
  var import_next = require("next-auth/next");
@@ -41,10 +45,9 @@ var TINA_CREDENTIALS_PROVIDER_NAME = "TinaCredentials";
41
45
 
42
46
  // src/index.ts
43
47
  var authenticate = async (databaseClient, username, password) => {
44
- var _a;
45
48
  try {
46
49
  const result = await databaseClient.authenticate({ username, password });
47
- return ((_a = result.data) == null ? void 0 : _a.authenticate) || null;
50
+ return result.data?.authenticate || null;
48
51
  } catch (e) {
49
52
  console.error(e);
50
53
  }
@@ -60,17 +63,16 @@ var TinaAuthJSOptions = ({
60
63
  }) => ({
61
64
  callbacks: {
62
65
  jwt: async ({ token: jwt, account }) => {
63
- var _a, _b, _c, _d;
64
66
  if (account) {
65
67
  if (debug) {
66
68
  console.table(jwt);
67
69
  }
68
70
  try {
69
- if (jwt == null ? void 0 : jwt[uidProp]) {
71
+ if (jwt?.[uidProp]) {
70
72
  const sub = jwt[uidProp];
71
73
  const result = await databaseClient.authorize({ sub });
72
- jwt.role = !!((_a = result.data) == null ? void 0 : _a.authorize) ? "user" : "guest";
73
- jwt.passwordChangeRequired = ((_d = (_c = (_b = result.data) == null ? void 0 : _b.authorize) == null ? void 0 : _c._password) == null ? void 0 : _d.passwordChangeRequired) || false;
74
+ jwt.role = !!result.data?.authorize ? "user" : "guest";
75
+ jwt.passwordChangeRequired = result.data?.authorize?._password?.passwordChangeRequired || false;
74
76
  } else if (debug) {
75
77
  console.log(`jwt missing specified uidProp: ${uidProp}`);
76
78
  }
@@ -84,7 +86,6 @@ var TinaAuthJSOptions = ({
84
86
  return jwt;
85
87
  },
86
88
  session: async ({ session, token: jwt }) => {
87
- ;
88
89
  session.user.role = jwt.role;
89
90
  session.user.passwordChangeRequired = jwt.passwordChangeRequired;
90
91
  session.user[uidProp] = jwt[uidProp];
@@ -115,8 +116,7 @@ var AuthJsBackendAuthProvider = ({
115
116
  }) => {
116
117
  const authProvider = {
117
118
  initialize: async () => {
118
- var _a;
119
- if (!((_a = authOptions.providers) == null ? void 0 : _a.length)) {
119
+ if (!authOptions.providers?.length) {
120
120
  throw new Error("No auth providers specified");
121
121
  }
122
122
  const [provider, ...rest] = authOptions.providers;
@@ -134,14 +134,14 @@ var AuthJsBackendAuthProvider = ({
134
134
  writable: false
135
135
  });
136
136
  }
137
- if (!(session == null ? void 0 : session.user)) {
137
+ if (!session?.user) {
138
138
  return {
139
139
  errorCode: 401,
140
140
  errorMessage: "Unauthorized",
141
141
  isAuthorized: false
142
142
  };
143
143
  }
144
- if ((session == null ? void 0 : session.user).role !== "user") {
144
+ if ((session?.user).role !== "user") {
145
145
  return {
146
146
  errorCode: 403,
147
147
  errorMessage: "Forbidden",
@@ -154,12 +154,11 @@ var AuthJsBackendAuthProvider = ({
154
154
  auth: {
155
155
  secure: false,
156
156
  handler: async (req, res, opts) => {
157
- var _a, _b, _c;
158
157
  const url = new URL(
159
158
  req.url,
160
- `http://${((_a = req.headers) == null ? void 0 : _a.host) || "localhost"}`
159
+ `http://${req.headers?.host || "localhost"}`
161
160
  );
162
- const authSubRoutes = (_c = (_b = url.pathname) == null ? void 0 : _b.replace(`${opts.basePath}auth/`, "")) == null ? void 0 : _c.split("/");
161
+ const authSubRoutes = url.pathname?.replace(`${opts.basePath}auth/`, "")?.split("/");
163
162
  req.query.nextauth = authSubRoutes;
164
163
  await (0, import_next_auth.default)(authOptions)(req, res);
165
164
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tinacms-authjs",
3
- "version": "0.0.0-f97a9b1-20241023074747",
3
+ "version": "0.0.0-f9fb00b-20250728042847",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "files": [
@@ -18,24 +18,24 @@
18
18
  ]
19
19
  },
20
20
  "dependencies": {
21
- "@tinacms/schema-tools": "1.6.6"
21
+ "@tinacms/schema-tools": "1.9.0"
22
22
  },
23
23
  "devDependencies": {
24
24
  "next": "14.2.10",
25
25
  "next-auth": "4.24.7",
26
26
  "react": "^18.3.1",
27
27
  "react-dom": "^18.3.1",
28
- "typescript": "^5.6.2",
29
- "@tinacms/datalayer": "1.3.6",
30
- "@tinacms/scripts": "1.3.0",
31
- "tinacms": "0.0.0-f97a9b1-20241023074747"
28
+ "typescript": "^5.7.3",
29
+ "@tinacms/datalayer": "1.4.0",
30
+ "@tinacms/scripts": "1.4.0",
31
+ "tinacms": "0.0.0-f9fb00b-20250728042847"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "next": "^12.2.5 || ^13 || ^14",
35
35
  "next-auth": "^4.22.1",
36
36
  "react": "^17.0.2 || ^18",
37
37
  "react-dom": "^17.0.2 || ^18",
38
- "tinacms": "0.0.0-f97a9b1-20241023074747"
38
+ "tinacms": "0.0.0-f9fb00b-20250728042847"
39
39
  },
40
40
  "publishConfig": {
41
41
  "registry": "https://registry.npmjs.org"