Skip to content

Commit 265b31e

Browse files
authored
Merge pull request #154 from accounts-js/feature/remove-user-unused-code
remove unused actions to store user
2 parents 5e3d5a9 + 6af1fce commit 265b31e

File tree

3 files changed

+0
-60
lines changed

3 files changed

+0
-60
lines changed

packages/client/__tests__/accounts-client.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -307,22 +307,6 @@ describe('Accounts', () => {
307307
expect(Accounts.instance.getState().get('tokens')).toEqual(null);
308308
}
309309
});
310-
311-
it('clear user in redux', async () => {
312-
const transport = {
313-
...mockTransport,
314-
logout: () => Promise.reject({ message: 'error message' }),
315-
};
316-
Accounts.instance.storeTokens({ accessToken: '1' });
317-
Accounts.config({ history }, transport);
318-
const callback = jest.fn();
319-
try {
320-
await Accounts.logout(callback);
321-
throw new Error();
322-
} catch (err) {
323-
expect(Accounts.instance.getState().get('user')).toEqual(null);
324-
}
325-
});
326310
});
327311

328312
describe('refreshSession', async () => {
@@ -332,13 +316,11 @@ describe('Accounts', () => {
332316
Accounts.instance.clearTokens = jest.fn(
333317
() => Accounts.instance.clearTokens
334318
);
335-
Accounts.instance.clearUser = jest.fn(() => Accounts.instance.clearUser);
336319
try {
337320
await Accounts.refreshSession();
338321
} catch (err) {
339322
expect(err.message).toEqual('no tokens provided');
340323
expect(Accounts.instance.clearTokens).toHaveBeenCalledTimes(1);
341-
expect(Accounts.instance.clearUser).toHaveBeenCalledTimes(1);
342324
}
343325
});
344326

@@ -349,7 +331,6 @@ describe('Accounts', () => {
349331
Accounts.instance.clearTokens = jest.fn(
350332
() => Accounts.instance.clearTokens
351333
);
352-
Accounts.instance.clearUser = jest.fn(() => Accounts.instance.clearUser);
353334
try {
354335
await Accounts.refreshSession();
355336
throw new Error();

packages/client/src/accounts-client.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import config, { TokenStorage, AccountsClientConfiguration } from './config';
1717
import createStore from './create-store';
1818
import reducer, {
1919
loggingIn,
20-
clearUser,
2120
setTokens,
2221
clearTokens as clearStoreTokens,
2322
setOriginalTokens,
@@ -122,12 +121,6 @@ export class AccountsClient {
122121
this.store.dispatch(setOriginalTokens(tokens));
123122
}
124123

125-
public user(): UserObjectType {
126-
const user = this.getState().get('user');
127-
128-
return user ? user.toJS() : null;
129-
}
130-
131124
public async impersonate(username: string): Promise<ImpersonateReturnType> {
132125
if (!isString(username)) {
133126
throw new AccountsError('Username is required');
@@ -239,10 +232,6 @@ export class AccountsClient {
239232
}
240233
}
241234

242-
public clearUser() {
243-
this.store.dispatch(clearUser());
244-
}
245-
246235
public async resumeSession(): Promise<void> {
247236
try {
248237
await this.refreshSession();
@@ -267,7 +256,6 @@ export class AccountsClient {
267256
// Refresh token is expired, user must sign back in
268257
if (decodedRefreshToken.exp < currentTime) {
269258
this.clearTokens();
270-
this.clearUser();
271259
} else {
272260
// Request a new token pair
273261
const refreshedSession: LoginReturnType = await this.transport.refreshTokens(
@@ -282,12 +270,10 @@ export class AccountsClient {
282270
} catch (err) {
283271
this.store.dispatch(loggingIn(false));
284272
this.clearTokens();
285-
this.clearUser();
286273
throw new AccountsError('falsy token provided');
287274
}
288275
} else {
289276
this.clearTokens();
290-
this.clearUser();
291277
throw new AccountsError('no tokens provided');
292278
}
293279
}
@@ -364,7 +350,6 @@ export class AccountsClient {
364350
return response;
365351
} catch (err) {
366352
this.clearTokens();
367-
this.store.dispatch(clearUser());
368353
this.store.dispatch(loggingIn(false));
369354
throw new AccountsError(err.message);
370355
}
@@ -387,7 +372,6 @@ export class AccountsClient {
387372
}
388373

389374
this.clearTokens();
390-
this.store.dispatch(clearUser());
391375
if (callback && isFunction(callback)) {
392376
callback();
393377
}
@@ -397,7 +381,6 @@ export class AccountsClient {
397381
}
398382
} catch (err) {
399383
this.clearTokens();
400-
this.store.dispatch(clearUser());
401384
if (callback && isFunction(callback)) {
402385
callback(err);
403386
}
@@ -435,9 +418,6 @@ const Accounts = {
435418

436419
return this.instance;
437420
},
438-
user(): UserObjectType | null {
439-
return this.instance.user();
440-
},
441421
options(): AccountsClientConfiguration {
442422
return this.instance.options;
443423
},

packages/client/src/module.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@ import { Map } from 'immutable';
22

33
const PATH = 'js-accounts/';
44
const LOGIN = `${PATH}LOGIN`;
5-
const SET_USER = `${PATH}SET_USER`;
65
const SET_TOKENS = `${PATH}SET_TOKENS`;
76
const CLEAR_TOKENS = `${PATH}CLEAR_TOKENS`;
8-
const CLEAR_USER = `${PATH}CLEAR_USER`;
97
const LOGGING_IN = `${PATH}LOGGING_IN`;
108
const SET_ORIGINAL_TOKENS = `${PATH}SET_ORIGINAL_TOKENS`;
119
const CLEAR_ORIGINAL_TOKENS = `${PATH}CLEAR_ORIGINAL_TOKENS`;
1210
const SET_IMPERSONATED = `${PATH}SET_IMPERSONATED`;
1311

1412
const initialState = Map<string, any>({
1513
isLoading: false,
16-
user: null,
1714
tokens: null,
1815
loggingIn: false,
1916
originalTokens: null,
@@ -26,10 +23,6 @@ const reducer = (state = initialState, action) => {
2623
case LOGIN: {
2724
break;
2825
}
29-
case SET_USER: {
30-
const { user } = action.payload;
31-
return state.set('user', Map(user));
32-
}
3326
case SET_TOKENS: {
3427
const { tokens } = action.payload;
3528
return state.set('tokens', Map(tokens));
@@ -38,9 +31,6 @@ const reducer = (state = initialState, action) => {
3831
state.set('originalTokens', null);
3932
return state.set('tokens', null);
4033
}
41-
case CLEAR_USER: {
42-
return state.set('user', null);
43-
}
4434
case LOGGING_IN: {
4535
const { isLoggingIn } = action.payload;
4636
return state.set('loggingIn', isLoggingIn);
@@ -75,13 +65,6 @@ export const loggingIn = isLoggingIn => ({
7565
},
7666
});
7767

78-
export const setUser = user => ({
79-
type: SET_USER,
80-
payload: {
81-
user,
82-
},
83-
});
84-
8568
export const setTokens = tokens => ({
8669
type: SET_TOKENS,
8770
payload: {
@@ -93,10 +76,6 @@ export const clearTokens = () => ({
9376
type: CLEAR_TOKENS,
9477
});
9578

96-
export const clearUser = () => ({
97-
type: CLEAR_USER,
98-
});
99-
10079
export const setOriginalTokens = tokens => ({
10180
type: SET_ORIGINAL_TOKENS,
10281
payload: {

0 commit comments

Comments
 (0)