Manage Client Side Tokens with aws-amplify JS Library

0

Context I am using aws-amplify to manage authentication -- however, I am not using the prebuilt AWS React UI component. The primary use case is to generate an identity / access token on the client side, which is passed to the server via HTTP headers. The server then verifies the token is valid with a call to getUser.

Client side, I know tokens can be requested via

await Auth.currentSession().then( value => {
      return value.getAccessToken().getJwtToken()
})

Question I am unsure what the best practice for managing and updating these tokens are within a React application. Should I just call the above code snippet whenever I need a token? Should I somehow wrap it in a context?

Furthermore, I occasionally need the token in a synchronous context. For example, one use case is to reroute users to a login page if they are not currently logged in. How should I do this?

If anyone has successfully implemented an end-to-end pipeline with AWS and React with custom sign-in / sign-up pages, let me know how you solved this.

1개 답변
0

Have you checked this aws-sample: https://github.com/aws-samples/amazon-cognito-authentication-sample-react-app

I hope it helps you.

Regards

AWS
답변함 8달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠