Skip to content

Commit

Permalink
fix(jwt): token logic not correct
Browse files Browse the repository at this point in the history
  • Loading branch information
yociduo committed Jan 2, 2020
1 parent 91e49b6 commit 9199e58
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions client/src/app.wpy
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default class extends wepy.app {
return data;
case 401:
wepy.redirectTo({ url: 'welcome' });
wepy.removeStorageSync(TOKEN_KEY);
return null;
default:
return null;
Expand Down
4 changes: 2 additions & 2 deletions server/src/util/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ export function decryptData(encryptedData: string, iv: string, sessionKey: strin

export function sign({ id, nickName }: User): string {
return jwt.sign({ id }, config.jwtSecret, {
expiresIn: nickName ? null : '1d',
expiresIn: nickName ? 10 : '1d',
});
}

export function verify(token: string) {
const data = jwt.verify(token.slice(7), config.jwtSecret);
const data = jwt.verify(token.startsWith('Bearer ') ? token.slice(7) : token, config.jwtSecret);
if (typeof data === 'string') {
return Number(data);
}
Expand Down

0 comments on commit 9199e58

Please sign in to comment.