Skip to content

Commit

Permalink
feat: allows for refresh operation to accept a deliberately specified…
Browse files Browse the repository at this point in the history
… token
  • Loading branch information
jmikrut committed Jan 2, 2021
1 parent 4d871c2 commit 7d05069
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/auth/graphql/resolvers/refresh.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
const getExtractJWT = require('../../getExtractJWT');
import getExtractJWT from '../../getExtractJWT';

function refresh(collection) {
async function resolver(_, __, context) {
async function resolver(_, args, context) {
let token;

const extractJWT = getExtractJWT(this.config);
const token = extractJWT(context.req);
token = extractJWT(context.req);

if (args.token) {
token = args.token;
}

const options = {
collection,
Expand Down
8 changes: 7 additions & 1 deletion src/auth/requestHandlers/refresh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ import { PayloadRequest } from '../../express/types';

export default async function refreshHandler(req: PayloadRequest, res: Response, next: NextFunction): Promise<any> {
try {
let token;

const extractJWT = getExtractJWT(this.config);
const token = extractJWT(req);
token = extractJWT(req);

if (req.body.token) {
token = req.body.token;
}

const result = await this.operations.collections.auth.refresh({
req,
Expand Down
3 changes: 3 additions & 0 deletions src/collections/graphql/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ function registerCollections(): void {
},
},
}),
args: {
token: { type: GraphQLString },
},
resolve: refresh(collection),
};
}
Expand Down

0 comments on commit 7d05069

Please sign in to comment.