@opensaas/keystone-nextjs-auth 27.0.0 → 27.1.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @opensaas-keystone/nextjs-auth
2
2
 
3
+ ## 27.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - dd2923f: Fixes custom Prisma Path config
8
+
3
9
  ## 27.0.0
4
10
 
5
11
  ### Major Changes
@@ -8,6 +8,7 @@ export type NextAuthTemplateProps = {
8
8
  listKey: string;
9
9
  sessionData: string | undefined;
10
10
  sessionSecret: string;
11
+ prismaClientPath: string;
11
12
  };
12
13
  export type CoreNextAuthPageProps = {
13
14
  cookies?: Partial<CookiesOptions>;
@@ -1,2 +1,2 @@
1
1
  import { NextAuthTemplateProps } from '../pages/NextAuthPage';
2
- export declare const authTemplate: ({ autoCreate, identityField, listKey, sessionData, sessionSecret, }: NextAuthTemplateProps) => string;
2
+ export declare const authTemplate: ({ autoCreate, identityField, listKey, sessionData, sessionSecret, prismaClientPath, }: NextAuthTemplateProps) => string;
@@ -9,6 +9,7 @@ var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instan
9
9
  var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
10
10
  var _startsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/starts-with');
11
11
  var url = require('url');
12
+ var path = require('path');
12
13
  var react = require('next-auth/react');
13
14
  var jwt = require('next-auth/jwt');
14
15
  var cookie = require('cookie');
@@ -41,6 +42,7 @@ var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstancePro
41
42
  var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
42
43
  var _startsWithInstanceProperty__default = /*#__PURE__*/_interopDefault(_startsWithInstanceProperty);
43
44
  var url__default = /*#__PURE__*/_interopDefault(url);
45
+ var path__default = /*#__PURE__*/_interopDefault(path);
44
46
  var cookie__namespace = /*#__PURE__*/_interopNamespace(cookie);
45
47
  var ejs__default = /*#__PURE__*/_interopDefault(ejs);
46
48
  var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
@@ -118,7 +120,7 @@ const template = `
118
120
  import { getContext } from '@keystone-6/core/context';
119
121
  import getNextAuthPage from '@opensaas/keystone-nextjs-auth/pages/NextAuthPage';
120
122
  import keystoneConfig from '../../../../../keystone';
121
- import * as PrismaModule from '.prisma/client';
123
+ import * as PrismaModule from '<%= prismaClientPath %>';
122
124
 
123
125
  const keystoneQueryAPI = global.keystoneQueryAPI || getContext(keystoneConfig, PrismaModule).sudo().query;
124
126
 
@@ -142,14 +144,16 @@ const authTemplate = _ref => {
142
144
  identityField,
143
145
  listKey,
144
146
  sessionData,
145
- sessionSecret
147
+ sessionSecret,
148
+ prismaClientPath
146
149
  } = _ref;
147
150
  const authOut = ejs__default["default"].render(template, {
148
151
  identityField,
149
152
  sessionData,
150
153
  listKey,
151
154
  autoCreate,
152
- sessionSecret
155
+ sessionSecret,
156
+ prismaClientPath
153
157
  });
154
158
  return authOut;
155
159
  };
@@ -197,8 +201,7 @@ function createAuth(_ref) {
197
201
  wasAccessAllowed
198
202
  } = _ref2;
199
203
  const {
200
- req,
201
- session
204
+ req
202
205
  } = context;
203
206
  const pathname = url__default["default"].parse(req === null || req === void 0 ? void 0 : req.url).pathname;
204
207
  if (wasAccessAllowed) {
@@ -210,7 +213,7 @@ function createAuth(_ref) {
210
213
  }
211
214
  return;
212
215
  }
213
- if (!session && !_includesInstanceProperty__default["default"](pathname).call(pathname, `${customPath}/api/auth/`)) {
216
+ if (!wasAccessAllowed && !_includesInstanceProperty__default["default"](pathname).call(pathname, `${customPath}/api/auth/`)) {
214
217
  return {
215
218
  kind: 'redirect',
216
219
  to: (pages === null || pages === void 0 ? void 0 : pages.signIn) || `${customPath}/api/auth/signin`
@@ -226,7 +229,8 @@ function createAuth(_ref) {
226
229
  *
227
230
  * The signin page is always included, and the init page is included when initFirstItem is set
228
231
  */
229
- const authGetAdditionalFiles = () => {
232
+ const authGetAdditionalFiles = config => {
233
+ const prismaClientPath = config.db.prismaClientPath ? path__default["default"].join('../../../../../', config.db.prismaClientPath) : '@prisma/client';
230
234
  const filesToWrite = [{
231
235
  mode: 'write',
232
236
  outputPath: 'pages/api/auth/[...nextauth].js',
@@ -235,7 +239,8 @@ function createAuth(_ref) {
235
239
  identityField,
236
240
  listKey,
237
241
  sessionData,
238
- sessionSecret
242
+ sessionSecret,
243
+ prismaClientPath
239
244
  })
240
245
  }, {
241
246
  mode: 'write',
@@ -9,6 +9,7 @@ var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instan
9
9
  var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
10
10
  var _startsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/starts-with');
11
11
  var url = require('url');
12
+ var path = require('path');
12
13
  var react = require('next-auth/react');
13
14
  var jwt = require('next-auth/jwt');
14
15
  var cookie = require('cookie');
@@ -41,6 +42,7 @@ var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstancePro
41
42
  var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
42
43
  var _startsWithInstanceProperty__default = /*#__PURE__*/_interopDefault(_startsWithInstanceProperty);
43
44
  var url__default = /*#__PURE__*/_interopDefault(url);
45
+ var path__default = /*#__PURE__*/_interopDefault(path);
44
46
  var cookie__namespace = /*#__PURE__*/_interopNamespace(cookie);
45
47
  var ejs__default = /*#__PURE__*/_interopDefault(ejs);
46
48
  var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
@@ -118,7 +120,7 @@ const template = `
118
120
  import { getContext } from '@keystone-6/core/context';
119
121
  import getNextAuthPage from '@opensaas/keystone-nextjs-auth/pages/NextAuthPage';
120
122
  import keystoneConfig from '../../../../../keystone';
121
- import * as PrismaModule from '.prisma/client';
123
+ import * as PrismaModule from '<%= prismaClientPath %>';
122
124
 
123
125
  const keystoneQueryAPI = global.keystoneQueryAPI || getContext(keystoneConfig, PrismaModule).sudo().query;
124
126
 
@@ -142,14 +144,16 @@ const authTemplate = _ref => {
142
144
  identityField,
143
145
  listKey,
144
146
  sessionData,
145
- sessionSecret
147
+ sessionSecret,
148
+ prismaClientPath
146
149
  } = _ref;
147
150
  const authOut = ejs__default["default"].render(template, {
148
151
  identityField,
149
152
  sessionData,
150
153
  listKey,
151
154
  autoCreate,
152
- sessionSecret
155
+ sessionSecret,
156
+ prismaClientPath
153
157
  });
154
158
  return authOut;
155
159
  };
@@ -197,8 +201,7 @@ function createAuth(_ref) {
197
201
  wasAccessAllowed
198
202
  } = _ref2;
199
203
  const {
200
- req,
201
- session
204
+ req
202
205
  } = context;
203
206
  const pathname = url__default["default"].parse(req === null || req === void 0 ? void 0 : req.url).pathname;
204
207
  if (wasAccessAllowed) {
@@ -210,7 +213,7 @@ function createAuth(_ref) {
210
213
  }
211
214
  return;
212
215
  }
213
- if (!session && !_includesInstanceProperty__default["default"](pathname).call(pathname, `${customPath}/api/auth/`)) {
216
+ if (!wasAccessAllowed && !_includesInstanceProperty__default["default"](pathname).call(pathname, `${customPath}/api/auth/`)) {
214
217
  return {
215
218
  kind: 'redirect',
216
219
  to: (pages === null || pages === void 0 ? void 0 : pages.signIn) || `${customPath}/api/auth/signin`
@@ -226,7 +229,8 @@ function createAuth(_ref) {
226
229
  *
227
230
  * The signin page is always included, and the init page is included when initFirstItem is set
228
231
  */
229
- const authGetAdditionalFiles = () => {
232
+ const authGetAdditionalFiles = config => {
233
+ const prismaClientPath = config.db.prismaClientPath ? path__default["default"].join('../../../../../', config.db.prismaClientPath) : '@prisma/client';
230
234
  const filesToWrite = [{
231
235
  mode: 'write',
232
236
  outputPath: 'pages/api/auth/[...nextauth].js',
@@ -235,7 +239,8 @@ function createAuth(_ref) {
235
239
  identityField,
236
240
  listKey,
237
241
  sessionData,
238
- sessionSecret
242
+ sessionSecret,
243
+ prismaClientPath
239
244
  })
240
245
  }, {
241
246
  mode: 'write',
@@ -5,6 +5,7 @@ import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance
5
5
  import _JSON$stringify from '@babel/runtime-corejs3/core-js-stable/json/stringify';
6
6
  import _startsWithInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/starts-with';
7
7
  import url from 'url';
8
+ import path from 'path';
8
9
  import { getSession } from 'next-auth/react';
9
10
  import { getToken } from 'next-auth/jwt';
10
11
  import * as cookie from 'cookie';
@@ -85,7 +86,7 @@ const template = `
85
86
  import { getContext } from '@keystone-6/core/context';
86
87
  import getNextAuthPage from '@opensaas/keystone-nextjs-auth/pages/NextAuthPage';
87
88
  import keystoneConfig from '../../../../../keystone';
88
- import * as PrismaModule from '.prisma/client';
89
+ import * as PrismaModule from '<%= prismaClientPath %>';
89
90
 
90
91
  const keystoneQueryAPI = global.keystoneQueryAPI || getContext(keystoneConfig, PrismaModule).sudo().query;
91
92
 
@@ -109,14 +110,16 @@ const authTemplate = _ref => {
109
110
  identityField,
110
111
  listKey,
111
112
  sessionData,
112
- sessionSecret
113
+ sessionSecret,
114
+ prismaClientPath
113
115
  } = _ref;
114
116
  const authOut = ejs.render(template, {
115
117
  identityField,
116
118
  sessionData,
117
119
  listKey,
118
120
  autoCreate,
119
- sessionSecret
121
+ sessionSecret,
122
+ prismaClientPath
120
123
  });
121
124
  return authOut;
122
125
  };
@@ -164,8 +167,7 @@ function createAuth(_ref) {
164
167
  wasAccessAllowed
165
168
  } = _ref2;
166
169
  const {
167
- req,
168
- session
170
+ req
169
171
  } = context;
170
172
  const pathname = url.parse(req === null || req === void 0 ? void 0 : req.url).pathname;
171
173
  if (wasAccessAllowed) {
@@ -177,7 +179,7 @@ function createAuth(_ref) {
177
179
  }
178
180
  return;
179
181
  }
180
- if (!session && !_includesInstanceProperty(pathname).call(pathname, `${customPath}/api/auth/`)) {
182
+ if (!wasAccessAllowed && !_includesInstanceProperty(pathname).call(pathname, `${customPath}/api/auth/`)) {
181
183
  return {
182
184
  kind: 'redirect',
183
185
  to: (pages === null || pages === void 0 ? void 0 : pages.signIn) || `${customPath}/api/auth/signin`
@@ -193,7 +195,8 @@ function createAuth(_ref) {
193
195
  *
194
196
  * The signin page is always included, and the init page is included when initFirstItem is set
195
197
  */
196
- const authGetAdditionalFiles = () => {
198
+ const authGetAdditionalFiles = config => {
199
+ const prismaClientPath = config.db.prismaClientPath ? path.join('../../../../../', config.db.prismaClientPath) : '@prisma/client';
197
200
  const filesToWrite = [{
198
201
  mode: 'write',
199
202
  outputPath: 'pages/api/auth/[...nextauth].js',
@@ -202,7 +205,8 @@ function createAuth(_ref) {
202
205
  identityField,
203
206
  listKey,
204
207
  sessionData,
205
- sessionSecret
208
+ sessionSecret,
209
+ prismaClientPath
206
210
  })
207
211
  }, {
208
212
  mode: 'write',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opensaas/keystone-nextjs-auth",
3
- "version": "27.0.0",
3
+ "version": "27.1.0",
4
4
  "repository": "https://github.com/opensaasau/keystone-nextjs-auth",
5
5
  "license": "MIT",
6
6
  "main": "dist/opensaas-keystone-nextjs-auth.cjs.js",
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import url from 'url';
2
+ import path from 'path';
2
3
  import {
3
4
  AdminFileToWrite,
4
5
  BaseListTypeInfo,
@@ -63,7 +64,7 @@ export function createAuth<GeneratedListTypes extends BaseListTypeInfo>({
63
64
  context,
64
65
  wasAccessAllowed,
65
66
  }) => {
66
- const { req, session } = context;
67
+ const { req } = context;
67
68
  const pathname = url.parse(req?.url!).pathname!;
68
69
 
69
70
  if (wasAccessAllowed) {
@@ -72,7 +73,7 @@ export function createAuth<GeneratedListTypes extends BaseListTypeInfo>({
72
73
  }
73
74
  return;
74
75
  }
75
- if (!session && !pathname.includes(`${customPath}/api/auth/`)) {
76
+ if (!wasAccessAllowed && !pathname.includes(`${customPath}/api/auth/`)) {
76
77
  return {
77
78
  kind: 'redirect',
78
79
  to: pages?.signIn || `${customPath}/api/auth/signin`,
@@ -88,7 +89,10 @@ export function createAuth<GeneratedListTypes extends BaseListTypeInfo>({
88
89
  *
89
90
  * The signin page is always included, and the init page is included when initFirstItem is set
90
91
  */
91
- const authGetAdditionalFiles = () => {
92
+ const authGetAdditionalFiles = (config: KeystoneConfig) => {
93
+ const prismaClientPath = config.db.prismaClientPath
94
+ ? path.join('../../../../../', config.db.prismaClientPath)
95
+ : '@prisma/client';
92
96
  const filesToWrite: AdminFileToWrite[] = [
93
97
  {
94
98
  mode: 'write',
@@ -99,6 +103,7 @@ export function createAuth<GeneratedListTypes extends BaseListTypeInfo>({
99
103
  listKey,
100
104
  sessionData,
101
105
  sessionSecret,
106
+ prismaClientPath,
102
107
  }),
103
108
  },
104
109
  {
@@ -10,6 +10,7 @@ export type NextAuthTemplateProps = {
10
10
  listKey: string;
11
11
  sessionData: string | undefined;
12
12
  sessionSecret: string;
13
+ prismaClientPath: string;
13
14
  };
14
15
 
15
16
  export type CoreNextAuthPageProps = {
@@ -5,7 +5,7 @@ const template = `
5
5
  import { getContext } from '@keystone-6/core/context';
6
6
  import getNextAuthPage from '@opensaas/keystone-nextjs-auth/pages/NextAuthPage';
7
7
  import keystoneConfig from '../../../../../keystone';
8
- import * as PrismaModule from '.prisma/client';
8
+ import * as PrismaModule from '<%= prismaClientPath %>';
9
9
 
10
10
  const keystoneQueryAPI = global.keystoneQueryAPI || getContext(keystoneConfig, PrismaModule).sudo().query;
11
11
 
@@ -30,6 +30,7 @@ export const authTemplate = ({
30
30
  listKey,
31
31
  sessionData,
32
32
  sessionSecret,
33
+ prismaClientPath,
33
34
  }: NextAuthTemplateProps) => {
34
35
  const authOut = ejs.render(template, {
35
36
  identityField,
@@ -37,6 +38,7 @@ export const authTemplate = ({
37
38
  listKey,
38
39
  autoCreate,
39
40
  sessionSecret,
41
+ prismaClientPath,
40
42
  });
41
43
  return authOut;
42
44
  };