-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework session handling and shrink jwt session cookie
- Loading branch information
Showing
17 changed files
with
127 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {Account, SessionAccount} from '@/types/Account'; | ||
import {SessionUser, User} from '@/types/User'; | ||
|
||
const createSessionAccount = (account: Account): SessionAccount => { | ||
return { | ||
_id: account._id.toString(), | ||
serverURL: account.serverURL, | ||
name: account.name, | ||
username: account.username, | ||
accountName: account.accountName, | ||
accountURL: account.accountURL, | ||
avatarURL: account.avatarURL, | ||
utcOffset: account.utcOffset, | ||
timezone: account.timezone, | ||
}; | ||
}; | ||
|
||
const createSessionUser = (user: User): SessionUser => { | ||
return { | ||
_id: user._id.toString(), | ||
role: user.role, | ||
email: user.email, | ||
emailVerified: user.emailVerified, | ||
accounts: user.accounts?.map(createSessionAccount), | ||
maxAccounts: user.maxAccounts, | ||
serverURLOnSignUp: user.serverURLOnSignUp, | ||
timezone: user.timezone, | ||
}; | ||
}; | ||
|
||
export default createSessionUser; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import postJSON from '@/helpers/postJSON'; | ||
import {AppDispatch} from '@/redux/store'; | ||
import {User} from '@/types/User'; | ||
import {SessionUser} from '@/types/User'; | ||
import {logoutSuccessful} from '../slice'; | ||
|
||
export const logout = (user: User) => async (dispatch: AppDispatch) => { | ||
export const logout = (user: SessionUser) => async (dispatch: AppDispatch) => { | ||
await postJSON('/api/user/logout', user); | ||
dispatch(logoutSuccessful()); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,12 @@ | ||
import get from '@/helpers/get'; | ||
import {AppDispatch} from '@/redux/store'; | ||
import {User} from '@/types/User'; | ||
import jwt from 'jsonwebtoken'; | ||
import {loginSuccessful} from '../slice'; | ||
|
||
export const refresh = () => async (dispatch: AppDispatch) => { | ||
const response = await get('/api/user/refresh'); | ||
|
||
if (response.status === 200) { | ||
const {token} = await response.data; | ||
const user = jwt.decode(token) as User; | ||
const {user} = await response.data; | ||
dispatch(loginSuccessful(user)); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.