Skip to content

Commit ef2c80e

Browse files
authored
Merge pull request #69 from js-accounts/fix
Throw error if no tokens are set when resuming session
2 parents 62f41de + 5423db6 commit ef2c80e

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

packages/client/src/AccountsClient.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ export class AccountsClient {
144144
} else {
145145
this.clearTokens();
146146
this.clearUser();
147+
throw new AccountsError('no tokens provided');
147148
}
148149
}
149150

packages/client/src/AccountsClient.spec.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,13 @@ describe('Accounts', () => {
336336
Accounts.config({}, {});
337337
Accounts.instance.clearTokens = jest.fn(() => Accounts.instance.clearTokens);
338338
Accounts.instance.clearUser = jest.fn(() => Accounts.instance.clearUser);
339-
await Accounts.refreshSession();
340-
expect(Accounts.instance.clearTokens.mock.calls.length).toEqual(1);
341-
expect(Accounts.instance.clearUser.mock.calls.length).toEqual(1);
339+
try {
340+
await Accounts.refreshSession();
341+
} catch (err) {
342+
expect(err.message).toEqual('no tokens provided');
343+
expect(Accounts.instance.clearTokens.mock.calls.length).toEqual(1);
344+
expect(Accounts.instance.clearUser.mock.calls.length).toEqual(1);
345+
}
342346
});
343347
it('clears tokens, users and throws error if bad refresh token provided', async () => {
344348
Accounts.config({}, {});

packages/client/src/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default {
2121
profilePath: '/',
2222
changePasswordPath: null,
2323
homePath: '/',
24+
signOutPath: '/',
2425
// TODO enable all of these
2526
// onSubmitHook: () => {},
2627
// onPreSignUpHook: () => new Promise(resolve => resolve()),
@@ -29,6 +30,6 @@ export default {
2930
onResetPasswordHook: () => redirect(AccountsClient.options().loginPath),
3031
onVerifyEmailHook: () => redirect(AccountsClient.options().profilePath),
3132
onSignedInHook: () => redirect(AccountsClient.options().homePath),
32-
onSignedOutHook: () => redirect(AccountsClient.options().homePath),
33+
onSignedOutHook: () => redirect(AccountsClient.options().signOutPath),
3334
loginOnSignUp: true,
3435
};

0 commit comments

Comments
 (0)