diff --git a/test/api/v3/integration/user/auth/POST-auth_reset-password-set-new-one.js b/test/api/v3/integration/user/auth/POST-auth_reset-password-set-new-one.js index 472872988d..25ae9e7c5d 100644 --- a/test/api/v3/integration/user/auth/POST-auth_reset-password-set-new-one.js +++ b/test/api/v3/integration/user/auth/POST-auth_reset-password-set-new-one.js @@ -238,6 +238,28 @@ describe('POST /user/auth/reset-password-set-new-one', () => { expect(isPassValid).to.equal(true); }); + it('changes the apiToken on password reset', async () => { + const user = await generateUser(); + const previousToken = user.apiToken; + + const code = encrypt(JSON.stringify({ + userId: user._id, + expiresAt: moment().add({ days: 1 }), + })); + await user.updateOne({ + 'auth.local.passwordResetCode': code, + }); + + await api.post(`${endpoint}`, { + newPassword: 'my new password', + confirmPassword: 'my new password', + code, + }); + + await user.sync(); + expect(user.apiToken).to.not.eql(previousToken); + }); + it('renders the success page and convert the password from sha1 to bcrypt', async () => { const user = await generateUser(); diff --git a/test/api/v3/integration/user/auth/PUT-user_update_password.test.js b/test/api/v3/integration/user/auth/PUT-user_update_password.test.js index 916e377a7f..6b764d7e1b 100644 --- a/test/api/v3/integration/user/auth/PUT-user_update_password.test.js +++ b/test/api/v3/integration/user/auth/PUT-user_update_password.test.js @@ -27,11 +27,30 @@ describe('PUT /user/auth/update-password', async () => { newPassword, confirmPassword: newPassword, }); - expect(response).to.eql({}); + + expect(response).to.exist; + expect(response.apiToken).to.exist; + await user.sync(); expect(user.auth.local.hashed_password).to.not.eql(previousHashedPassword); }); + it('should change the apiToken on password change', async () => { + const previousToken = user.apiToken; + const response = await user.put(ENDPOINT, { + password, + newPassword, + confirmPassword: newPassword, + }); + + const newToken = response.apiToken; + expect(newToken).to.exist; + + await user.sync(); + expect(user.apiToken).to.eql(newToken); + expect(user.apiToken).to.not.eql(previousToken); + }); + it('returns an error when confirmPassword does not match newPassword', async () => { await expect(user.put(ENDPOINT, { password, diff --git a/website/client/src/app.vue b/website/client/src/app.vue index 2b1215b6df..839b297e0a 100644 --- a/website/client/src/app.vue +++ b/website/client/src/app.vue @@ -111,6 +111,7 @@ import axios from 'axios'; import * as Analytics from '@/libs/analytics'; import { mapState } from '@/libs/store'; import snackbars from '@/components/snackbars/notifications'; +import { LOCALSTORAGE_AUTH_KEY } from '@/libs/auth'; const COMMUNITY_MANAGER_EMAIL = import.meta.env.EMAILS_COMMUNITY_MANAGER_EMAIL; @@ -280,7 +281,7 @@ export default { this.loading = false; }, checkForBannedUser (error) { - const AUTH_SETTINGS = localStorage.getItem('habit-mobile-settings'); + const AUTH_SETTINGS = localStorage.getItem(LOCALSTORAGE_AUTH_KEY); const parseSettings = JSON.parse(AUTH_SETTINGS); const errorMessage = error.response.data.message; diff --git a/website/client/src/components/bannedAccountModal.vue b/website/client/src/components/bannedAccountModal.vue index 7825605a06..3d77931247 100644 --- a/website/client/src/components/bannedAccountModal.vue +++ b/website/client/src/components/bannedAccountModal.vue @@ -30,6 +30,7 @@