@nixxie-cms/auth 1.0.1
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/LICENSE +21 -0
- package/README.md +6 -0
- package/components/Navigation/dist/nixxie-cms-auth-components-Navigation.cjs.d.ts +3 -0
- package/components/Navigation/dist/nixxie-cms-auth-components-Navigation.cjs.js +147 -0
- package/components/Navigation/dist/nixxie-cms-auth-components-Navigation.esm.js +143 -0
- package/components/Navigation/package.json +4 -0
- package/dist/declarations/src/components/Navigation.d.ts +6 -0
- package/dist/declarations/src/components/Navigation.d.ts.map +1 -0
- package/dist/declarations/src/index.d.ts +15 -0
- package/dist/declarations/src/index.d.ts.map +1 -0
- package/dist/declarations/src/pages/InitPage.d.ts +9 -0
- package/dist/declarations/src/pages/InitPage.d.ts.map +1 -0
- package/dist/declarations/src/pages/SigninPage.d.ts +9 -0
- package/dist/declarations/src/pages/SigninPage.d.ts.map +1 -0
- package/dist/declarations/src/types.d.ts +49 -0
- package/dist/declarations/src/types.d.ts.map +1 -0
- package/dist/nixxie-cms-auth.cjs.d.ts +2 -0
- package/dist/nixxie-cms-auth.cjs.js +552 -0
- package/dist/nixxie-cms-auth.esm.js +548 -0
- package/dist/useFromRedirect-2de239a9.cjs.js +26 -0
- package/dist/useFromRedirect-b3deee00.esm.js +24 -0
- package/package.json +56 -0
- package/pages/InitPage/dist/nixxie-cms-auth-pages-InitPage.cjs.d.ts +3 -0
- package/pages/InitPage/dist/nixxie-cms-auth-pages-InitPage.cjs.js +274 -0
- package/pages/InitPage/dist/nixxie-cms-auth-pages-InitPage.esm.js +266 -0
- package/pages/InitPage/package.json +4 -0
- package/pages/SigninPage/dist/nixxie-cms-auth-pages-SigninPage.cjs.d.ts +3 -0
- package/pages/SigninPage/dist/nixxie-cms-auth-pages-SigninPage.cjs.js +319 -0
- package/pages/SigninPage/dist/nixxie-cms-auth-pages-SigninPage.esm.js +311 -0
- package/pages/SigninPage/package.json +4 -0
- package/src/components/Navigation.tsx +182 -0
- package/src/gql/getBaseAuthSchema.ts +129 -0
- package/src/gql/getInitFirstItemSchema.ts +87 -0
- package/src/index.ts +291 -0
- package/src/lib/useFromRedirect.ts +23 -0
- package/src/pages/InitPage.tsx +292 -0
- package/src/pages/SigninPage.tsx +331 -0
- package/src/schema.ts +84 -0
- package/src/templates/config.ts +9 -0
- package/src/templates/init.ts +22 -0
- package/src/templates/signin.ts +20 -0
- package/src/types.ts +57 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default function ({ labelField }: { labelField: string }) {
|
|
2
|
+
return `import { type AdminConfig } from '@nixxie-cms/core/types'
|
|
3
|
+
import makeNavigation from '@nixxie-cms/auth/components/Navigation'
|
|
4
|
+
|
|
5
|
+
export const components: AdminConfig['components'] = {
|
|
6
|
+
Navigation: makeNavigation({ labelField: '${labelField}' }),
|
|
7
|
+
}
|
|
8
|
+
`
|
|
9
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { BaseListTypeInfo } from '@nixxie-cms/core/types'
|
|
2
|
+
import type { AuthGqlNames, AuthConfig } from '../types'
|
|
3
|
+
|
|
4
|
+
export default function ({
|
|
5
|
+
authGqlNames,
|
|
6
|
+
listKey,
|
|
7
|
+
initFirstItem,
|
|
8
|
+
}: {
|
|
9
|
+
authGqlNames: AuthGqlNames
|
|
10
|
+
listKey: string
|
|
11
|
+
initFirstItem: NonNullable<AuthConfig<BaseListTypeInfo>['initFirstItem']>
|
|
12
|
+
}) {
|
|
13
|
+
return `import makeInitPage from '@nixxie-cms/auth/pages/InitPage'
|
|
14
|
+
|
|
15
|
+
export default makeInitPage(${JSON.stringify({
|
|
16
|
+
listKey,
|
|
17
|
+
authGqlNames,
|
|
18
|
+
fieldPaths: initFirstItem.fields,
|
|
19
|
+
enableWelcome: !initFirstItem.skipNixxieWelcome,
|
|
20
|
+
})})
|
|
21
|
+
`
|
|
22
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AuthGqlNames } from '../types'
|
|
2
|
+
|
|
3
|
+
export default function ({
|
|
4
|
+
authGqlNames,
|
|
5
|
+
identityField,
|
|
6
|
+
secretField,
|
|
7
|
+
}: {
|
|
8
|
+
authGqlNames: AuthGqlNames
|
|
9
|
+
identityField: string
|
|
10
|
+
secretField: string
|
|
11
|
+
}) {
|
|
12
|
+
return `import makeSigninPage from '@nixxie-cms/auth/pages/SigninPage'
|
|
13
|
+
|
|
14
|
+
export default makeSigninPage(${JSON.stringify({
|
|
15
|
+
authGqlNames,
|
|
16
|
+
identityField,
|
|
17
|
+
secretField,
|
|
18
|
+
})})
|
|
19
|
+
`
|
|
20
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { BaseListTypeInfo, NixxieContext } from '@nixxie-cms/core/types'
|
|
2
|
+
|
|
3
|
+
export type AuthGqlNames = {
|
|
4
|
+
itemQueryName: string
|
|
5
|
+
whereUniqueInputName: string
|
|
6
|
+
|
|
7
|
+
authenticateItemWithPassword: string
|
|
8
|
+
ItemAuthenticationWithPasswordResult: string
|
|
9
|
+
ItemAuthenticationWithPasswordSuccess: string
|
|
10
|
+
ItemAuthenticationWithPasswordFailure: string
|
|
11
|
+
|
|
12
|
+
CreateInitialInput: string
|
|
13
|
+
createInitialItem: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type SendTokenFn = (args: {
|
|
17
|
+
itemId: string | number | bigint
|
|
18
|
+
identity: string
|
|
19
|
+
token: string
|
|
20
|
+
context: NixxieContext
|
|
21
|
+
}) => Promise<void> | void
|
|
22
|
+
|
|
23
|
+
export type AuthTokenTypeConfig = {
|
|
24
|
+
/** Called when a user should be sent the magic signin token they requested */
|
|
25
|
+
sendToken: SendTokenFn
|
|
26
|
+
/** How long do tokens stay valid for from time of issue, in minutes **/
|
|
27
|
+
tokensValidForMins?: number
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type AuthConfig<ListTypeInfo extends BaseListTypeInfo> = {
|
|
31
|
+
/** The key of the list to authenticate users with */
|
|
32
|
+
listKey: ListTypeInfo['key']
|
|
33
|
+
/** The path of the field the identity is stored in; must be text-ish */
|
|
34
|
+
identityField: ListTypeInfo['fields']
|
|
35
|
+
/** The path of the field the secret is stored in; must be password-ish */
|
|
36
|
+
secretField: ListTypeInfo['fields']
|
|
37
|
+
/** The initial user/db seeding functionality */
|
|
38
|
+
initFirstItem?: InitFirstItemConfig<ListTypeInfo>
|
|
39
|
+
/** Session data population */
|
|
40
|
+
sessionData?: string
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type InitFirstItemConfig<ListTypeInfo extends BaseListTypeInfo> = {
|
|
44
|
+
/** Array of fields to collect, e.g ['name', 'email', 'password'] */
|
|
45
|
+
fields: readonly ListTypeInfo['fields'][]
|
|
46
|
+
/** Suppresses the second screen where we ask people to subscribe and follow Nixxie */
|
|
47
|
+
skipNixxieWelcome?: boolean
|
|
48
|
+
/** Extra input to add for the create mutation */
|
|
49
|
+
itemData?: Partial<ListTypeInfo['inputs']['create']>
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type AuthTokenRedemptionErrorCode = 'FAILURE' | 'TOKEN_EXPIRED' | 'TOKEN_REDEEMED'
|
|
53
|
+
|
|
54
|
+
export type SecretFieldImpl = {
|
|
55
|
+
generateHash: (secret: string) => Promise<string>
|
|
56
|
+
compare: (secret: string, hash: string) => Promise<boolean>
|
|
57
|
+
}
|