tinacms-authjs 0.0.0-ebe1b69-20250211022853 → 0.0.0-ec43c87-20250804021103

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
@@ -27,13 +27,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
28
 
29
29
  // src/index.ts
30
- var src_exports = {};
31
- __export(src_exports, {
30
+ var index_exports = {};
31
+ __export(index_exports, {
32
32
  AuthJsBackendAuthProvider: () => AuthJsBackendAuthProvider,
33
33
  TinaAuthJSOptions: () => TinaAuthJSOptions,
34
34
  TinaCredentialsProvider: () => TinaCredentialsProvider
35
35
  });
36
- module.exports = __toCommonJS(src_exports);
36
+ module.exports = __toCommonJS(index_exports);
37
37
  var import_next_auth = __toESM(require("next-auth"));
38
38
  var import_credentials = __toESM(require("next-auth/providers/credentials"));
39
39
  var import_next = require("next-auth/next");
@@ -45,10 +45,9 @@ var TINA_CREDENTIALS_PROVIDER_NAME = "TinaCredentials";
45
45
 
46
46
  // src/index.ts
47
47
  var authenticate = async (databaseClient, username, password) => {
48
- var _a;
49
48
  try {
50
49
  const result = await databaseClient.authenticate({ username, password });
51
- return ((_a = result.data) == null ? void 0 : _a.authenticate) || null;
50
+ return result.data?.authenticate || null;
52
51
  } catch (e) {
53
52
  console.error(e);
54
53
  }
@@ -64,17 +63,16 @@ var TinaAuthJSOptions = ({
64
63
  }) => ({
65
64
  callbacks: {
66
65
  jwt: async ({ token: jwt, account }) => {
67
- var _a, _b, _c, _d;
68
66
  if (account) {
69
67
  if (debug) {
70
68
  console.table(jwt);
71
69
  }
72
70
  try {
73
- if (jwt == null ? void 0 : jwt[uidProp]) {
71
+ if (jwt?.[uidProp]) {
74
72
  const sub = jwt[uidProp];
75
73
  const result = await databaseClient.authorize({ sub });
76
- jwt.role = !!((_a = result.data) == null ? void 0 : _a.authorize) ? "user" : "guest";
77
- 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;
78
76
  } else if (debug) {
79
77
  console.log(`jwt missing specified uidProp: ${uidProp}`);
80
78
  }
@@ -88,7 +86,6 @@ var TinaAuthJSOptions = ({
88
86
  return jwt;
89
87
  },
90
88
  session: async ({ session, token: jwt }) => {
91
- ;
92
89
  session.user.role = jwt.role;
93
90
  session.user.passwordChangeRequired = jwt.passwordChangeRequired;
94
91
  session.user[uidProp] = jwt[uidProp];
@@ -119,8 +116,7 @@ var AuthJsBackendAuthProvider = ({
119
116
  }) => {
120
117
  const authProvider = {
121
118
  initialize: async () => {
122
- var _a;
123
- if (!((_a = authOptions.providers) == null ? void 0 : _a.length)) {
119
+ if (!authOptions.providers?.length) {
124
120
  throw new Error("No auth providers specified");
125
121
  }
126
122
  const [provider, ...rest] = authOptions.providers;
@@ -138,14 +134,14 @@ var AuthJsBackendAuthProvider = ({
138
134
  writable: false
139
135
  });
140
136
  }
141
- if (!(session == null ? void 0 : session.user)) {
137
+ if (!session?.user) {
142
138
  return {
143
139
  errorCode: 401,
144
140
  errorMessage: "Unauthorized",
145
141
  isAuthorized: false
146
142
  };
147
143
  }
148
- if ((session == null ? void 0 : session.user).role !== "user") {
144
+ if ((session?.user).role !== "user") {
149
145
  return {
150
146
  errorCode: 403,
151
147
  errorMessage: "Forbidden",
@@ -158,12 +154,11 @@ var AuthJsBackendAuthProvider = ({
158
154
  auth: {
159
155
  secure: false,
160
156
  handler: async (req, res, opts) => {
161
- var _a, _b, _c;
162
157
  const url = new URL(
163
158
  req.url,
164
- `http://${((_a = req.headers) == null ? void 0 : _a.host) || "localhost"}`
159
+ `http://${req.headers?.host || "localhost"}`
165
160
  );
166
- 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("/");
167
162
  req.query.nextauth = authSubRoutes;
168
163
  await (0, import_next_auth.default)(authOptions)(req, res);
169
164
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tinacms-authjs",
3
- "version": "0.0.0-ebe1b69-20250211022853",
3
+ "version": "0.0.0-ec43c87-20250804021103",
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.7.0"
21
+ "@tinacms/schema-tools": "0.0.0-ec43c87-20250804021103"
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.3",
29
- "tinacms": "0.0.0-ebe1b69-20250211022853",
30
- "@tinacms/datalayer": "0.0.0-ebe1b69-20250211022853",
31
- "@tinacms/scripts": "1.3.1"
28
+ "typescript": "^5.7.3",
29
+ "@tinacms/datalayer": "0.0.0-ec43c87-20250804021103",
30
+ "tinacms": "0.0.0-ec43c87-20250804021103",
31
+ "@tinacms/scripts": "1.4.0"
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-ebe1b69-20250211022853"
38
+ "tinacms": "0.0.0-ec43c87-20250804021103"
39
39
  },
40
40
  "publishConfig": {
41
41
  "registry": "https://registry.npmjs.org"