@accounts/client
Advanced tools
Comparing version 0.1.0-beta.2 to 0.1.0-beta.3
import { Map } from 'immutable'; | ||
import { CreateUserType, LoginReturnType, UserObjectType, TokensType, ImpersonateReturnType } from '@accounts/common'; | ||
import { CreateUserType, LoginReturnType, TokensType, ImpersonateReturnType } from '@accounts/common'; | ||
import { AccountsClientConfiguration } from './config'; | ||
@@ -18,3 +18,2 @@ import { TransportInterface } from './transport-interface'; | ||
loadOriginalTokensFromStorage(): Promise<void>; | ||
user(): UserObjectType; | ||
impersonate(username: string): Promise<ImpersonateReturnType>; | ||
@@ -28,3 +27,2 @@ stopImpersonation(): Promise<void>; | ||
storeOriginalTokens(tokens: TokensType): Promise<void>; | ||
clearUser(): void; | ||
resumeSession(): Promise<void>; | ||
@@ -45,3 +43,2 @@ refreshSession(): Promise<void>; | ||
config(options: AccountsClientConfiguration, transport: TransportInterface): Promise<AccountsClient>; | ||
user(): UserObjectType; | ||
options(): AccountsClientConfiguration; | ||
@@ -48,0 +45,0 @@ createUser(user: CreateUserType, callback?: (err?: Error) => void): Promise<void>; |
@@ -168,6 +168,2 @@ "use strict"; | ||
}; | ||
AccountsClient.prototype.user = function () { | ||
var user = this.getState().get('user'); | ||
return user ? user.toJS() : null; | ||
}; | ||
AccountsClient.prototype.impersonate = function (username) { | ||
@@ -321,5 +317,2 @@ return __awaiter(this, void 0, void 0, function () { | ||
}; | ||
AccountsClient.prototype.clearUser = function () { | ||
this.store.dispatch(module_1.clearUser()); | ||
}; | ||
AccountsClient.prototype.resumeSession = function () { | ||
@@ -350,3 +343,3 @@ return __awaiter(this, void 0, void 0, function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _a, accessToken, refreshToken, decodedRefreshToken, currentTime, refreshedSession, err_2; | ||
var _a, accessToken, refreshToken, currentTime, decodedAccessToken, decodedRefreshToken, refreshedSession, err_2; | ||
return __generator(this, function (_b) { | ||
@@ -362,18 +355,22 @@ switch (_b.label) { | ||
this.store.dispatch(module_1.loggingIn(true)); | ||
currentTime = Date.now() / 1000; | ||
decodedAccessToken = jwtDecode(accessToken); | ||
decodedRefreshToken = jwtDecode(refreshToken); | ||
currentTime = Date.now() / 1000; | ||
if (!(decodedRefreshToken.exp < currentTime)) return [3, 3]; | ||
this.clearTokens(); | ||
this.clearUser(); | ||
return [3, 6]; | ||
case 3: return [4, this.transport.refreshTokens(accessToken, refreshToken)]; | ||
case 4: | ||
if (!(decodedAccessToken.exp < currentTime)) return [3, 5]; | ||
return [4, this.transport.refreshTokens(accessToken, refreshToken)]; | ||
case 3: | ||
refreshedSession = _b.sent(); | ||
this.store.dispatch(module_1.loggingIn(false)); | ||
return [4, this.storeTokens(refreshedSession.tokens)]; | ||
case 5: | ||
case 4: | ||
_b.sent(); | ||
this.store.dispatch(module_1.setTokens(refreshedSession.tokens)); | ||
return [3, 6]; | ||
case 5: | ||
if (decodedRefreshToken.exp < currentTime) { | ||
this.clearTokens(); | ||
} | ||
_b.label = 6; | ||
case 6: return [3, 8]; | ||
case 6: | ||
this.store.dispatch(module_1.loggingIn(false)); | ||
return [3, 8]; | ||
case 7: | ||
@@ -383,3 +380,2 @@ err_2 = _b.sent(); | ||
this.clearTokens(); | ||
this.clearUser(); | ||
throw new common_1.AccountsError('falsy token provided'); | ||
@@ -389,3 +385,2 @@ case 8: return [3, 10]; | ||
this.clearTokens(); | ||
this.clearUser(); | ||
throw new common_1.AccountsError('no tokens provided'); | ||
@@ -480,3 +475,2 @@ case 10: return [2]; | ||
this.clearTokens(); | ||
this.store.dispatch(module_1.clearUser()); | ||
this.store.dispatch(module_1.loggingIn(false)); | ||
@@ -512,3 +506,2 @@ throw new common_1.AccountsError(err_6.message); | ||
this.clearTokens(); | ||
this.store.dispatch(module_1.clearUser()); | ||
if (callback && lodash_1.isFunction(callback)) { | ||
@@ -524,3 +517,2 @@ callback(); | ||
this.clearTokens(); | ||
this.store.dispatch(module_1.clearUser()); | ||
if (callback && lodash_1.isFunction(callback)) { | ||
@@ -577,5 +569,2 @@ callback(err_7); | ||
}, | ||
user: function () { | ||
return this.instance.user(); | ||
}, | ||
options: function () { | ||
@@ -582,0 +571,0 @@ return this.instance.options; |
@@ -10,8 +10,2 @@ import { Map } from 'immutable'; | ||
}; | ||
export declare const setUser: (user: any) => { | ||
type: string; | ||
payload: { | ||
user: any; | ||
}; | ||
}; | ||
export declare const setTokens: (tokens: any) => { | ||
@@ -26,5 +20,2 @@ type: string; | ||
}; | ||
export declare const clearUser: () => { | ||
type: string; | ||
}; | ||
export declare const setOriginalTokens: (tokens: any) => { | ||
@@ -31,0 +22,0 @@ type: string; |
@@ -6,6 +6,4 @@ "use strict"; | ||
var LOGIN = PATH + "LOGIN"; | ||
var SET_USER = PATH + "SET_USER"; | ||
var SET_TOKENS = PATH + "SET_TOKENS"; | ||
var CLEAR_TOKENS = PATH + "CLEAR_TOKENS"; | ||
var CLEAR_USER = PATH + "CLEAR_USER"; | ||
var LOGGING_IN = PATH + "LOGGING_IN"; | ||
@@ -17,3 +15,2 @@ var SET_ORIGINAL_TOKENS = PATH + "SET_ORIGINAL_TOKENS"; | ||
isLoading: false, | ||
user: null, | ||
tokens: null, | ||
@@ -31,6 +28,2 @@ loggingIn: false, | ||
} | ||
case SET_USER: { | ||
var user = action.payload.user; | ||
return state.set('user', immutable_1.Map(user)); | ||
} | ||
case SET_TOKENS: { | ||
@@ -44,5 +37,2 @@ var tokens = action.payload.tokens; | ||
} | ||
case CLEAR_USER: { | ||
return state.set('user', null); | ||
} | ||
case LOGGING_IN: { | ||
@@ -75,8 +65,2 @@ var isLoggingIn = action.payload.isLoggingIn; | ||
}); }; | ||
exports.setUser = function (user) { return ({ | ||
type: SET_USER, | ||
payload: { | ||
user: user, | ||
}, | ||
}); }; | ||
exports.setTokens = function (tokens) { return ({ | ||
@@ -91,5 +75,2 @@ type: SET_TOKENS, | ||
}); }; | ||
exports.clearUser = function () { return ({ | ||
type: CLEAR_USER, | ||
}); }; | ||
exports.setOriginalTokens = function (tokens) { return ({ | ||
@@ -96,0 +77,0 @@ type: SET_ORIGINAL_TOKENS, |
{ | ||
"name": "@accounts/client", | ||
"version": "0.1.0-beta.2", | ||
"version": "0.1.0-beta.3", | ||
"description": "Fullstack authentication and accounts-management", | ||
@@ -51,5 +51,5 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@types/jest": "20.0.8", | ||
"jest": "20.0.4", | ||
"jsonwebtoken": "7.4.3", | ||
"@types/jest": "22.2.0", | ||
"jest": "22.4.2", | ||
"jsonwebtoken": "8.2.0", | ||
"lerna": "2.9.0", | ||
@@ -61,3 +61,3 @@ "localstorage-polyfill": "1.0.1", | ||
"dependencies": { | ||
"@accounts/common": "^0.1.0-beta.2", | ||
"@accounts/common": "^0.1.0-beta.3", | ||
"crypto-js": "^3.1.9-1", | ||
@@ -68,4 +68,4 @@ "immutable": "^3.8.1", | ||
"redux": "^3.7.2", | ||
"redux-immutable": "^3.0.8" | ||
"redux-immutable": "^4.0.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59138
970
+ Addedredux-immutable@4.0.0(transitive)
- Removedredux-immutable@3.1.0(transitive)
Updatedredux-immutable@^4.0.0