LoginSignup
5
11

More than 3 years have passed since last update.

Amplifyを使って任意のタイミングでIDトークン、アクセストークンを更新する

Last updated at Posted at 2019-12-20

概要

Amplifyを使って任意のタイミングでIDトークン、アクセストークンを更新する。

実装

一度認証されているのが前提。

Amplifyにはそれ用の口がない(っぽい)ので、Amazon Cognito Identity SDK の機能を使って更新する。

import { Auth } from "aws-amplify";

const cognitoUser = await Auth.currentAuthenticatedUser();
const currentSession = await Auth.currentSession();

cognitoUser.refreshSession(currentSession.refreshToken, (err, session) => {
    console.log('session', err, session);
    const { idToken, refreshToken, accessToken } = session;
});

参考

5
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
11