Skip to content

Commit

Permalink
Merge pull request Organisasjonskollegiet#172 from Organisasjonskolle…
Browse files Browse the repository at this point in the history
…giet/feat/change_password

feat: provide change password links for Auth0
  • Loading branch information
schjoth authored Jun 10, 2022
2 parents 8c7560f + 379679b commit 16f3060
Show file tree
Hide file tree
Showing 5 changed files with 31 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.

1 change: 1 addition & 0 deletions src/lib/permissions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const permissions = shield(
and(isParticipantOfVotation, resultIsPublished, votesNotHidden)
),
numberOfUpcomingVotations: and(isParticipantOfMeeting),
updateMyPassword: and(isAuthenticated),
},
Mutation: {
addParticipants: and(isAdminOfMeetingId),
Expand Down
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 16f3060

Please sign in to comment.