Skip to content

Commit

Permalink
feat: provide change password links for Auth0
Browse files Browse the repository at this point in the history
  • Loading branch information
schjoth committed Mar 20, 2022
1 parent 287f9f6 commit 9a5e8d5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/__generated__/nexus-typegen.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/__generated__/schema.graphql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/schema/auth/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const DeleteUserMutation = mutationField('deleteMe', {
description: 'Delete your own user.',
args: {},
resolve: async (_, __, ctx) => {
var auth0 = new ManagementClient({
const auth0 = new ManagementClient({
domain: process.env.AUTH0_DOMAIN!,
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
Expand Down
24 changes: 24 additions & 0 deletions src/schema/auth/query.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ManagementClient } from 'auth0';
import { queryField } from 'nexus';
import { GetUserResult } from './typedefs/results';
import { EXPOSED_USER_FIELDS } from './utils';
Expand All @@ -13,3 +14,26 @@ export const UserQuery = queryField('user', {
return { __typename: 'User', ...user };
},
});

export const UpdatePasswordLinkQuery = queryField('updateMyPassword', {
type: 'String',
description: 'Provides a ticket to change Auth0 password.',
args: {},
resolve: async (_, __, ctx) => {
const auth0 = new ManagementClient({
domain: process.env.AUTH0_DOMAIN!,
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
// scope: 'delete:users'
});

const res = auth0.createPasswordChangeTicket({
user_id: `auth0|${ctx.userId}`,
ttl_sec: 1200,
includeEmailInRedirect: false,
result_url: process.env.AUTH0_CALLBACK_URL,
});

return (await res).ticket;
},
});

0 comments on commit 9a5e8d5

Please sign in to comment.