@opensaas/keystone-nextjs-auth 21.1.1 → 22.2.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 +26 -0
- package/dist/declarations/src/index.d.ts +3 -3
- package/dist/declarations/src/pages/NextAuthPage.d.ts +17 -12
- package/dist/declarations/src/templates/auth.d.ts +2 -4
- package/dist/declarations/src/templates/next-config.d.ts +1 -1
- package/dist/declarations/src/{types.d.ts → types/index.d.ts} +29 -8
- package/dist/opensaas-keystone-nextjs-auth.cjs.dev.js +64 -49
- package/dist/opensaas-keystone-nextjs-auth.cjs.prod.js +63 -48
- package/dist/opensaas-keystone-nextjs-auth.esm.js +64 -49
- package/package.json +2 -4
- package/pages/NextAuthPage/dist/opensaas-keystone-nextjs-auth-pages-NextAuthPage.cjs.dev.js +49 -38
- package/pages/NextAuthPage/dist/opensaas-keystone-nextjs-auth-pages-NextAuthPage.cjs.prod.js +49 -38
- package/pages/NextAuthPage/dist/opensaas-keystone-nextjs-auth-pages-NextAuthPage.esm.js +49 -37
- package/src/gql/getBaseAuthSchema.ts +1 -4
- package/src/index.ts +96 -86
- package/src/lib/findMatchingIdentity.ts +1 -4
- package/src/pages/NextAuthPage.tsx +58 -71
- package/src/schema.ts +2 -4
- package/src/templates/auth.ts +12 -5
- package/src/templates/next-config.ts +1 -5
- package/src/{types.ts → types/index.ts} +28 -11
- package/src/types/next-auth.d.ts +19 -0
package/src/templates/auth.ts
CHANGED
@@ -1,10 +1,19 @@
|
|
1
1
|
import ejs from 'ejs';
|
2
|
-
import {
|
2
|
+
import { NextAuthTemplateProps } from '../pages/NextAuthPage';
|
3
3
|
|
4
4
|
const template = `
|
5
5
|
import getNextAuthPage from '@opensaas/keystone-nextjs-auth/pages/NextAuthPage';
|
6
|
-
import { query } from '.keystone/api';
|
7
6
|
import keystoneConfig from '../../../../../keystone';
|
7
|
+
import { PrismaClient } from '.prisma/client';
|
8
|
+
import { createQueryAPI } from '@keystone-6/core/___internal-do-not-use-will-break-in-patch/node-api';
|
9
|
+
|
10
|
+
const prisma = global.prisma || PrismaClient
|
11
|
+
|
12
|
+
if (process.env.NODE_ENV !== 'production') global.prisma = prisma
|
13
|
+
|
14
|
+
const query = global.query || createQueryAPI(keystoneConfig, prisma);
|
15
|
+
|
16
|
+
if (process.env.NODE_ENV !== 'production') global.query = query
|
8
17
|
|
9
18
|
export default getNextAuthPage({
|
10
19
|
autoCreate: <%= autoCreate %>,
|
@@ -19,15 +28,13 @@ export default getNextAuthPage({
|
|
19
28
|
});
|
20
29
|
`;
|
21
30
|
|
22
|
-
type AuthTemplateOptions = NextAuthPageProps;
|
23
|
-
|
24
31
|
export const authTemplate = ({
|
25
32
|
autoCreate,
|
26
33
|
identityField,
|
27
34
|
listKey,
|
28
35
|
sessionData,
|
29
36
|
sessionSecret,
|
30
|
-
}:
|
37
|
+
}: NextAuthTemplateProps) => {
|
31
38
|
const authOut = ejs.render(template, {
|
32
39
|
identityField,
|
33
40
|
sessionData,
|
@@ -56,11 +56,7 @@ module.exports = withPreconstruct({
|
|
56
56
|
<% } %>
|
57
57
|
});
|
58
58
|
`;
|
59
|
-
export const nextConfigTemplate = ({
|
60
|
-
keystonePath,
|
61
|
-
}: {
|
62
|
-
keystonePath: string;
|
63
|
-
}) => {
|
59
|
+
export const nextConfigTemplate = ({ keystonePath }: { keystonePath: string }) => {
|
64
60
|
const nextConfigOut = ejs.render(template, { keystonePath });
|
65
61
|
|
66
62
|
return nextConfigOut;
|
@@ -1,8 +1,27 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
1
|
+
import type { ServerResponse, IncomingMessage } from 'http';
|
2
|
+
import type { NextRequest } from 'next/server';
|
3
3
|
import { Provider } from 'next-auth/providers';
|
4
|
+
import { CookiesOptions, PagesOptions } from 'next-auth';
|
5
|
+
import { BaseListTypeInfo, KeystoneConfig, CreateContext } from '@keystone-6/core/types';
|
4
6
|
|
5
|
-
|
7
|
+
type NextAuthResponse = IncomingMessage & NextRequest;
|
8
|
+
|
9
|
+
export declare type AuthSessionStrategy<StoredSessionData> = {
|
10
|
+
start: (args: {
|
11
|
+
res: ServerResponse;
|
12
|
+
data: any;
|
13
|
+
createContext: CreateContext;
|
14
|
+
}) => Promise<string>;
|
15
|
+
end: (args: {
|
16
|
+
req: IncomingMessage;
|
17
|
+
res: ServerResponse;
|
18
|
+
createContext: CreateContext;
|
19
|
+
}) => Promise<void>;
|
20
|
+
get: (args: {
|
21
|
+
req: NextAuthResponse;
|
22
|
+
createContext: CreateContext;
|
23
|
+
}) => Promise<StoredSessionData | undefined>;
|
24
|
+
};
|
6
25
|
|
7
26
|
export type NextAuthProviders = Provider[];
|
8
27
|
|
@@ -15,9 +34,7 @@ type NextAuthOptions = {
|
|
15
34
|
resolver: any;
|
16
35
|
};
|
17
36
|
|
18
|
-
export type KeystoneOAuthConfig = KeystoneConfig &
|
19
|
-
KeytoneOAuthOptions &
|
20
|
-
NextAuthOptions;
|
37
|
+
export type KeystoneOAuthConfig = KeystoneConfig & KeytoneOAuthOptions & NextAuthOptions;
|
21
38
|
|
22
39
|
export type AuthConfig<GeneratedListTypes extends BaseListTypeInfo> = {
|
23
40
|
/** Auth Create users in Keystone DB from Auth Provider */
|
@@ -31,20 +48,20 @@ export type AuthConfig<GeneratedListTypes extends BaseListTypeInfo> = {
|
|
31
48
|
/** Path for Keystone interface */
|
32
49
|
keystonePath?: string;
|
33
50
|
// Custom pages for different NextAuth events
|
34
|
-
pages?:
|
51
|
+
pages?: Partial<PagesOptions>;
|
35
52
|
/** Providers for Next Auth */
|
36
53
|
providers: NextAuthProviders;
|
37
54
|
/** Resolver for user to define their profile */
|
38
|
-
resolver?:
|
55
|
+
resolver?: (args: { user: any; profile: any; account: any }) => Promise<{
|
56
|
+
[key: string]: boolean | string | number;
|
57
|
+
}>;
|
39
58
|
/** Session data population */
|
40
59
|
sessionData?: string | undefined;
|
41
60
|
/** Next-Auth Session Secret */
|
42
61
|
sessionSecret: string;
|
43
62
|
};
|
44
63
|
|
45
|
-
export type AuthTokenRequestErrorCode =
|
46
|
-
| 'IDENTITY_NOT_FOUND'
|
47
|
-
| 'MULTIPLE_IDENTITY_MATCHES';
|
64
|
+
export type AuthTokenRequestErrorCode = 'IDENTITY_NOT_FOUND' | 'MULTIPLE_IDENTITY_MATCHES';
|
48
65
|
|
49
66
|
export type PasswordAuthErrorCode =
|
50
67
|
| AuthTokenRequestErrorCode
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import NextAuth from 'next-auth';
|
2
|
+
import { JWT } from 'next-auth/jwt';
|
3
|
+
|
4
|
+
declare module 'next-auth' {
|
5
|
+
interface JWT {
|
6
|
+
data?: any | undefined;
|
7
|
+
subject?: string | undefined;
|
8
|
+
listKey?: string;
|
9
|
+
itemId?: string | undefined;
|
10
|
+
name?: string | null | undefined;
|
11
|
+
email?: string | null | undefined;
|
12
|
+
picture?: string | null | undefined;
|
13
|
+
sub?: string | null | undefined;
|
14
|
+
expires?: string | null | undefined;
|
15
|
+
}
|
16
|
+
interface Session extends JWT {
|
17
|
+
user?: any;
|
18
|
+
}
|
19
|
+
}
|