Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no request when no token #26

Open
moparlakci opened this issue Dec 11, 2018 · 2 comments
Open

no request when no token #26

moparlakci opened this issue Dec 11, 2018 · 2 comments

Comments

@moparlakci
Copy link

Hi is there a way, to not to do a request when there is no jwt token in localStorage?
It should just render the login page

Now it is doing an unneccessary empty request, and the response is also empty. so the userInfo is null.
We should be able to skip that.., do you know how?

@karthikvt26
Copy link
Collaborator

What you can do is, wrap with AuthProvider only when the token is available in the localStorage. Otherwise don't wrap with AuthProvider?

For example: if you have a Login component which might need to check whether user has a valid session or not depending on whether token is available in the localStorage, here is how the React code will look like

...
...

const token =  ''; // Retrieve from the localStorage

{ token  ? (
    <AuthProvider authUrl={'https://website.com/get/userInfo'}>
        <Login { ...props } />
    </AuthProvider>
) : (
    <Login />
) }

...
...

Hope this helps. Feel free to reach out to us if you face any issues.

@moparlakci
Copy link
Author

My whole application is wrapped with the AuthProvider which has my App Router beneath.
Actually a prop in the AuthProvider could fix this very easily.. Like makeRequest={true || false} or so..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants