Skip to content

Commit

Permalink
ref: account password reset (#363)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredshema authored Oct 23, 2024
1 parent 51b182a commit 3138d6b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/resolvers/userResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,31 @@ const resolvers: any = {
throw new Error('Oopps! something went wrong')
}
},
async changeUserPassword(
_: any,
{ currentPassword, newPassword, confirmPassword, token }: any,
context: any
) {
const { userId } = verify(token, SECRET) as JwtPayload
if (newPassword === confirmPassword) {
const user: any = await User.findById(userId)
if (!user) {
throw new Error("User doesn't exist! ")
}

if (bcrypt.compareSync(currentPassword, user.password)) {
user.password = newPassword
await user.save()
return 'Your password was reset successfully! '
} else {
throw new Error('Current Password is incorrect')
}
} else if (newPassword !== confirmPassword) {
throw new Error('New password mismatch!')
} else {
throw new Error('Oopps! something went wrong')
}
},
},

User: {
Expand Down
6 changes: 6 additions & 0 deletions src/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@ const Schema = gql`
confirmPassword: String!
token: String!
): String!
changeUserPassword(
currentPassword: String!
newPassword: String!
confirmPassword: String!
token: String!
): String!
addActiveRepostoOrganization(name: String!, repoUrl: String!): Organization!
Expand Down

0 comments on commit 3138d6b

Please sign in to comment.