-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Factors out user hook to only HeaderNavBar
- Adds refetch to hook to get username after login - Changes auth slice to store the user to state in a way that gets picked up by userData
- Loading branch information
1 parent
09dbad7
commit 81e4a4f
Showing
5 changed files
with
54 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,28 @@ | ||
import { useSelector } from 'react-redux'; | ||
import { RootState } from '../../redux/store'; | ||
import { AuthenticatedUser } from '@hazmapper/types'; | ||
import { useState } from 'react'; | ||
|
||
type SuccessResult<T> = { | ||
data: T; | ||
isLoading: false; | ||
error: null; | ||
refetch: () => void; | ||
}; | ||
|
||
// TODO remove this placeholder hook | ||
const useAuthenticatedUser = (): SuccessResult<AuthenticatedUser> => { | ||
const [, forceRerender] = useState({}); | ||
let username = useSelector((state: RootState) => state.auth.user?.username); | ||
|
||
if (!username) { | ||
username = ''; | ||
} | ||
const refetch = () => { | ||
forceRerender({}); | ||
}; | ||
|
||
return { data: { username }, isLoading: false, error: null }; | ||
return { data: { username }, isLoading: false, error: null, refetch }; | ||
}; | ||
|
||
export default useAuthenticatedUser; |
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