Skip to content

Commit

Permalink
Fixes GraphQL errors when using @keystone-6/auth (#8182)
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Calder committed Dec 20, 2022
1 parent 71dbfe3 commit b52713b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/early-suns-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-6/auth': patch
---

Fixes GraphQL error when using `autoincrement` for auth list id
5 changes: 5 additions & 0 deletions .changeset/good-monkeys-complain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-6/auth': patch
---

Fixes GraphQL error when `sessionStrategy.start` returns null or undefined
13 changes: 10 additions & 3 deletions packages/auth/src/gql/getBaseAuthSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ export function getBaseAuthSchema<I extends string, S extends string>({
resolveType: (root, context) => context.session?.listKey,
}),
resolve(root, args, { session, db }) {
if (typeof session?.itemId === 'string' && typeof session.listKey === 'string') {
if (
(typeof session?.itemId === 'string' || typeof session.itemId === 'number') &&
typeof session.listKey === 'string'
) {
return db[session.listKey].findOne({ where: { id: session.itemId } });
}
return null;
Expand Down Expand Up @@ -88,13 +91,17 @@ export function getBaseAuthSchema<I extends string, S extends string>({
}

// Update system state
const sessionToken = (await context.sessionStrategy.start({
const sessionToken = await context.sessionStrategy.start({
data: {
listKey,
itemId: result.item.id,
},
context,
})) as string;
});
// return Failure if sessionStrategy.start() returns null
if (typeof sessionToken !== 'string' || sessionToken.length === 0) {
return { code: 'FAILURE', message: 'Failed to start session.' };
}
return { sessionToken, item: result.item };
},
}),
Expand Down

1 comment on commit b52713b

@vercel
Copy link

@vercel vercel bot commented on b52713b Dec 20, 2022

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.