Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie committed Apr 23, 2021
1 parent 1418aa8 commit 3f9077f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions packages-next/auth/src/gql/getBaseAuthSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ export function getBaseAuthSchema<I extends string, S extends string>({
}

const list = context.keystone.lists[listKey];
const itemAPI = context.sudo().lists[listKey];
const dbItemAPI = context.sudo().db.lists[listKey];
const result = await validateSecret(
list,
identityField,
args[identityField],
secretField,
protectIdentities,
args[secretField],
itemAPI
dbItemAPI
);

if (!result.success) {
Expand Down
6 changes: 3 additions & 3 deletions packages-next/auth/src/gql/getMagicAuthLinkSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export function getMagicAuthLinkSchema<I extends string>({
}

const list = context.keystone.lists[listKey];
const itemAPI = context.sudo().lists[listKey];
const dbItemAPI = context.sudo().db.lists[listKey];
const tokenType = 'magicAuth';
const result = await validateAuthToken(
tokenType,
Expand All @@ -117,7 +117,7 @@ export function getMagicAuthLinkSchema<I extends string>({
protectIdentities,
magicAuthLink.tokensValidForMins,
args.token,
itemAPI
dbItemAPI
);

if (!result.success) {
Expand All @@ -132,7 +132,7 @@ export function getMagicAuthLinkSchema<I extends string>({
}
// Update system state
// Save the token and related info back to the item
await itemAPI.updateOne({
await dbItemAPI.updateOne({
id: result.item.id,
data: { [`${tokenType}RedeemedAt`]: new Date().toISOString() },
});
Expand Down
12 changes: 6 additions & 6 deletions packages-next/auth/src/gql/getPasswordResetSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export function getPasswordResetSchema<I extends string, S extends string>({
context
) {
const list = context.keystone.lists[listKey];
const itemAPI = context.sudo().lists[listKey];
const dbItemAPI = context.sudo().db.lists[listKey];
const tokenType = 'passwordReset';
const result = await validateAuthToken(
tokenType,
Expand All @@ -118,7 +118,7 @@ export function getPasswordResetSchema<I extends string, S extends string>({
protectIdentities,
passwordResetLink.tokensValidForMins,
args.token,
itemAPI
dbItemAPI
);

if (!result.success) {
Expand All @@ -137,15 +137,15 @@ export function getPasswordResetSchema<I extends string, S extends string>({
// Update system state
const itemId = result.item.id;
// Save the token and related info back to the item
await itemAPI.updateOne({
await dbItemAPI.updateOne({
id: itemId,
data: { [`${tokenType}RedeemedAt`]: new Date().toISOString() },
});

// Save the provided secret. Do this as a separate step as password validation
// may fail, in which case we still want to mark the token as redeemed
// (NB: Is this *really* what we want? -TL)
await itemAPI.updateOne({
await dbItemAPI.updateOne({
id: itemId,
data: { [secretField]: args[secretField] },
});
Expand All @@ -160,7 +160,7 @@ export function getPasswordResetSchema<I extends string, S extends string>({
context
) {
const list = context.keystone.lists[listKey];
const itemAPI = context.sudo().lists[listKey];
const dbItemAPI = context.sudo().db.lists[listKey];
const tokenType = 'passwordReset';
const result = await validateAuthToken(
tokenType,
Expand All @@ -170,7 +170,7 @@ export function getPasswordResetSchema<I extends string, S extends string>({
protectIdentities,
passwordResetLink.tokensValidForMins,
args.token,
itemAPI
dbItemAPI
);

if (!result.success && result.code) {
Expand Down
6 changes: 3 additions & 3 deletions packages-next/auth/src/lib/validateAuthToken.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { KeystoneListsAPI } from '@keystone-next/types';
import type { KeystoneDbAPI } from '@keystone-next/types';
import { AuthTokenRedemptionErrorCode } from '../types';
import { validateSecret } from './validateSecret';

Expand All @@ -17,7 +17,7 @@ export async function validateAuthToken(
protectIdentities: boolean,
tokenValidMins: number | undefined,
token: string,
itemAPI: KeystoneListsAPI<any>[string]
dbItemAPI: KeystoneDbAPI<any>[string]
): Promise<
| { success: false; code: AuthTokenRedemptionErrorCode }
| { success: true; item: { id: any; [prop: string]: any } }
Expand All @@ -29,7 +29,7 @@ export async function validateAuthToken(
`${tokenType}Token`,
protectIdentities,
token,
itemAPI
dbItemAPI
);
if (!result.success) {
// Rewrite error codes
Expand Down

0 comments on commit 3f9077f

Please sign in to comment.