mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-05-31 14:11:58 +05:30
#244: Remove the code, that relied on old user state containing token
This commit is contained in:
@@ -25,11 +25,11 @@ export function factory(store) {
|
|||||||
promise = Promise.resolve()
|
promise = Promise.resolve()
|
||||||
.then(() => store.dispatch(logoutStrangers()))
|
.then(() => store.dispatch(logoutStrangers()))
|
||||||
.then(() => {
|
.then(() => {
|
||||||
const {user, accounts} = store.getState();
|
const {accounts} = store.getState();
|
||||||
|
|
||||||
if (accounts.active || user.token) {
|
if (accounts.active) {
|
||||||
// authorizing user if it is possible
|
// authorizing user if it is possible
|
||||||
return store.dispatch(authenticate(accounts.active || user));
|
return store.dispatch(authenticate(accounts.active));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.reject();
|
return Promise.reject();
|
||||||
|
@@ -12,9 +12,9 @@
|
|||||||
export default function bearerHeaderMiddleware({getState}) {
|
export default function bearerHeaderMiddleware({getState}) {
|
||||||
return {
|
return {
|
||||||
before(req) {
|
before(req) {
|
||||||
const {user, accounts} = getState();
|
const {accounts} = getState();
|
||||||
|
|
||||||
let {token} = accounts.active ? accounts.active : user;
|
let {token} = accounts.active || {};
|
||||||
|
|
||||||
if (req.options.token || req.options.token === null) {
|
if (req.options.token || req.options.token === null) {
|
||||||
token = req.options.token;
|
token = req.options.token;
|
||||||
|
@@ -62,28 +62,6 @@ describe('bearerHeaderMiddleware', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when legacy token available', () => {
|
|
||||||
const token = 'foo';
|
|
||||||
const middleware = bearerHeaderMiddleware({
|
|
||||||
getState: () => ({
|
|
||||||
...emptyState,
|
|
||||||
user: {token}
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should set Authorization header', () => {
|
|
||||||
let data = {
|
|
||||||
options: {
|
|
||||||
headers: {}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
data = middleware.before(data);
|
|
||||||
|
|
||||||
expectBearerHeader(data, token);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not set Authorization header if no token', () => {
|
it('should not set Authorization header if no token', () => {
|
||||||
const middleware = bearerHeaderMiddleware({
|
const middleware = bearerHeaderMiddleware({
|
||||||
getState: () => ({
|
getState: () => ({
|
||||||
|
Reference in New Issue
Block a user