Skip to content

Commit

Permalink
Improve auth types (#5008)
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie authored Mar 4, 2021
1 parent 2bf7101 commit 2674831
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/fresh-worms-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/auth': patch
---

Updated internal types to be more correct.
6 changes: 3 additions & 3 deletions packages-next/auth/src/gql/getInitFirstItemSchema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { GraphQLSchemaExtension, BaseKeystone } from '@keystone-next/types';

import { AuthGqlNames } from '../types';
import { AuthGqlNames, InitFirstItemConfig } from '../types';

export function getInitFirstItemSchema({
listKey,
Expand All @@ -10,8 +10,8 @@ export function getInitFirstItemSchema({
keystone,
}: {
listKey: string;
fields: string[];
itemData: Record<string, any> | undefined;
fields: InitFirstItemConfig<any>['fields'];
itemData: InitFirstItemConfig<any>['itemData'];
gqlNames: AuthGqlNames;
keystone: BaseKeystone;
}): GraphQLSchemaExtension {
Expand Down
6 changes: 3 additions & 3 deletions packages-next/auth/src/schema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { mergeSchemas } from '@graphql-tools/merge';
import { ExtendGraphqlSchema } from '@keystone-next/types';

import { AuthGqlNames, AuthTokenTypeConfig } from './types';
import { AuthGqlNames, AuthTokenTypeConfig, InitFirstItemConfig } from './types';
import { getBaseAuthSchema } from './gql/getBaseAuthSchema';
import { getInitFirstItemSchema } from './gql/getInitFirstItemSchema';
import { getPasswordResetSchema } from './gql/getPasswordResetSchema';
Expand All @@ -22,8 +22,8 @@ export const getSchemaExtension = ({
protectIdentities: boolean;
secretField: string;
gqlNames: AuthGqlNames;
initFirstItem?: any;
passwordResetLink?: any;
initFirstItem?: InitFirstItemConfig<any>;
passwordResetLink?: AuthTokenTypeConfig;
magicAuthLink?: AuthTokenTypeConfig;
}): ExtendGraphqlSchema => (schema, keystone) =>
[
Expand Down
18 changes: 10 additions & 8 deletions packages-next/auth/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@ export type AuthConfig<GeneratedListTypes extends BaseGeneratedListTypes> = {
/** "Magic link" functionality */
magicAuthLink?: AuthTokenTypeConfig;
/** The initial user/db seeding functionality */
initFirstItem?: {
/** Array of fields to collect, e.g ['name', 'email', 'password'] */
fields: GeneratedListTypes['fields'][];
/** Suppresses the second screen where we ask people to subscribe and follow Keystone */
skipKeystoneWelcome?: boolean;
/** Extra input to add for the create mutation */
itemData?: Partial<GeneratedListTypes['inputs']['create']>;
};
initFirstItem?: InitFirstItemConfig<GeneratedListTypes>;
};

export type InitFirstItemConfig<GeneratedListTypes extends BaseGeneratedListTypes> = {
/** Array of fields to collect, e.g ['name', 'email', 'password'] */
fields: GeneratedListTypes['fields'][];
/** Suppresses the second screen where we ask people to subscribe and follow Keystone */
skipKeystoneWelcome?: boolean;
/** Extra input to add for the create mutation */
itemData?: Partial<GeneratedListTypes['inputs']['create']>;
};

export type AuthTokenRequestErrorCode = 'IDENTITY_NOT_FOUND' | 'MULTIPLE_IDENTITY_MATCHES';
Expand Down

1 comment on commit 2674831

@vercel
Copy link

@vercel vercel bot commented on 2674831 Mar 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.