mercredi 11 mars 2020

is it possible to use if statement in calling REST api?

OS : Window 10
IDE TOOLS : VSC
node : v12.14.1

Hi i'm not good at English. so my expressions will be little bit awkward.
I'm using Spring boot REST API and client-side is react.js

I'm trying to use refresh Token, Access Token with jwt.

What i want to do is,

Before calling rest api, If accessToken is invalid with timeout in client side,
get Requesttoken in localStorage and send it to serverside and reinssuance accessToken and refreshToken.
And store it again. Then i call rest api what i want to call it first.

Here is my question.
Is it possible that Rest api has if statement ?

api.js

const getAccessToken = () => {
const accessToken = sessionStorage.getItem('accessToken');
if (!accessToken) {
    window.location.href = "http://localhost:3000";
    return alert('Login first');
} else if (accessToken && !validateToken()) {

// ~~~~ Here is what i want to ask~~~~
       is it possible in react.js???

    const refreshToken = localStorage.getItem("refreshToken");
    getAtWithRefreshToken(refreshToken); 
    sessionStorage.setItem('')
    return accessToken;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

} else if (accessToken && validateToken()) {
    console.log("token is Valid~~~");
    return accessToken;
}}


export const getBoardList = (searchType = '', searchString = '', page) =>
axios.get("http://localhost:8080/jpa/board/",
    {
        params: {
            searchType,
            searchString,
            page
        },
        headers: {
            'Authorization': getAccessToken()
        }

    }
)

This is my first Question in StackOverFlow...
Please Let me know in the comments if there is anything I need to explain.

Sorry you for you that spend many time in my promiscuous question.
Hope you guys always in healthy.

1 commentaire:

  1. Water Hack Burns 2 lb of Fat OVERNIGHT

    At least 160000 women and men are losing weight with a easy and secret "liquid hack" to lose 2lbs every night as they sleep.

    It's proven and it works with anybody.

    This is how you can do it yourself:

    1) Go grab a drinking glass and fill it up with water half glass

    2) Proceed to do this crazy HACK

    you'll be 2lbs skinnier the very next day!

    RépondreSupprimer