@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 +6 -0
- package/dist/declarations/src/pages/NextAuthPage.d.ts +1 -0
- package/dist/declarations/src/templates/auth.d.ts +1 -1
- package/dist/opensaas-keystone-nextjs-auth.cjs.dev.js +13 -8
- package/dist/opensaas-keystone-nextjs-auth.cjs.prod.js +13 -8
- package/dist/opensaas-keystone-nextjs-auth.esm.js +12 -8
- package/package.json +1 -1
- package/src/index.ts +8 -3
- package/src/pages/NextAuthPage.tsx +1 -0
- package/src/templates/auth.ts +3 -1
package/CHANGELOG.md
CHANGED
@@ -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 '
|
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 (!
|
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 '
|
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 (!
|
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 '
|
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 (!
|
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
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
|
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 (!
|
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
|
{
|
package/src/templates/auth.ts
CHANGED
@@ -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 '
|
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
|
};
|