Comments (5)
I don’t see how this library has anything to do with react navigation or conditional rendering.
from react-native-axios-jwt.
Thanks for this awesome tool! I'm facing the same issue @c0nsoleg tho: there is no way to react to when the user gets logged in or logged out in order to do something like:
const isLoggedIn = useIsUserLoggedIn();
if (isLoggedIn) {
return <HomeNavigation />;
}
return <AuthNavigation />;
You can answer with "this library is just for setting the axios headers interceptors" and you would be 100% right, but at the same time it would be nice to have the possibility to respond accordingly.
Thanks!
from react-native-axios-jwt.
Hi @ericlifs, have you tried using the isLoggedIn
function that is exported from this library? Check out the readme to learn how to use this library.
from react-native-axios-jwt.
Hey @mvanroon, how are you? Yes, I've tried using that isLoggedIn
function but it doesn't fit our requirement as it is an async function that returns a boolean indicating whether the user is logged at the time of calling the function or not. We were talking about having a hook that returns a boolean indicating when the headers are set or not, by doing that you can react to changes on this boolean and show different navigators accordingly.
Also, there is a "bug" in the readme file: this is the code for the isLoggedIn
function:
/**
* Checks if refresh tokens are stored
* @async
* @returns {Promise<boolean>} Whether the user is logged in or not
*/
export const isLoggedIn = async (): Promise<boolean> => {
const token = await getRefreshToken()
return !!token
}
If you do in your code:
if (isLoggedIn()) {
console.log('logged in')
} else {
console.log('not logged in')
}
It will always show 'logged in' because the isLoggedIn
function is an async function and therefore returns a Promise<boolean>
which is always true (you'll always need to await that call).
Eric.
from react-native-axios-jwt.
You’re right! Looks like the readme needs to be updated. Could you open a PR?
As for ‘caching’ the auth state. You could build this in your own project or we could create a hook that returns the logged in state. This state would need to be updated when a user logs in or out.
Wanna take a stab at it? I’m available for reviewing pull requests.
from react-native-axios-jwt.
Related Issues (9)
- Login State HOT 5
- Update axios package requirements HOT 3
- Can't install HOT 2
- [AxiosError: Unable to refresh access token for request due to token refresh error: Request failed with status code 400] HOT 2
- Could not resolve dependency: axios@"~0" HOT 1
- Comparison with `axios-jwt` library HOT 4
- isLoggedIn is always logged in, even when tokens are undefined or null. HOT 1
- Sending empty request HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-axios-jwt.