Skip to content

Commit 2fbbc02

Browse files
committed
fix authentication
1 parent 64ab479 commit 2fbbc02

5 files changed

Lines changed: 34 additions & 3 deletions

File tree

api/actions/auth/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export load from './load';

api/actions/auth/load.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import config from 'config';
2+
import { verifyJWT } from 'feathers-authentication/lib/utils';
3+
4+
export default function load(req) {
5+
const accessToken = req.cookies['feathers-jwt'] || null;
6+
7+
const defaultValues = {
8+
accessToken,
9+
user: null
10+
};
11+
12+
if (accessToken) {
13+
return verifyJWT(accessToken, config.auth)
14+
.then(payload => req.app.service('users').get(payload.userId))
15+
.then(user => ({
16+
accessToken,
17+
user
18+
}))
19+
.catch(() => defaultValues);
20+
}
21+
22+
return Promise.resolve(defaultValues);
23+
}

api/actions/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export loadInfo from './loadInfo';
2+
export * as auth from './auth';
23
export * as widget from './widget';
34
export * as survey from './survey';

src/containers/ChatFeathers/ChatFeathers.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ import { connect } from 'react-redux';
55
import { withApp } from 'app';
66
import * as chatActions from 'redux/modules/chat';
77

8-
@withApp
98
@asyncConnect([{
10-
promise: ({ store: { dispatch } }) => dispatch(chatActions.load())
9+
promise: ({ store: { dispatch, getState } }) => {
10+
const state = getState();
11+
12+
if (state.online) {
13+
return dispatch(chatActions.load());
14+
}
15+
}
1116
}])
1217
@connect(
1318
state => ({
@@ -16,6 +21,7 @@ import * as chatActions from 'redux/modules/chat';
1621
}),
1722
{ ...chatActions }
1823
)
24+
@withApp
1925
export default class ChatFeathers extends Component {
2026

2127
static propTypes = {

src/redux/modules/auth.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export function isLoaded(globalState) {
140140
export function load() {
141141
return {
142142
types: [LOAD, LOAD_SUCCESS, LOAD_FAIL],
143-
promise: ({ app }) => app.authenticate()
143+
promise: ({ client }) => client.get('/auth/load')
144144
};
145145
}
146146

0 commit comments

Comments
 (0)