开发者

Auth.currentSession() is returning expired JWT token in react native

I am trying to fetch JWT token every time a user opens app and store it in the local storage by overwriting it with old JWT token. But Auth.currentSession() is returning the expired JWT token.


useEffect(() => {
    try {
      const fetchToken = async () => {
        let authToken = await AsyncStorage.getItem("token");
        console.log("authToken in hook:", authToken);        // old token
        if (authToken) {
          authToken = await (await Auth.currentSession())
            .getAccessToken()
            .getJwtToken();
          setToken(authToken);
          const loggedInUserInfo = await Auth.currentUserInfo();
          setUserInfo(loggedInUserInfo.attributes);
          await AsyncStorage.setItem("token", authToken);
          console.log("token resestted with new one", authToken);  // expired/old token
          setIsLoggedIn(true);
        }
      };
 开发者_运维问答     fetchToken();
    } catch (err) {
      console.log(err);
    }
  }, []);

How can I handle this expiration of jwt token?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜