LoginSignup
18
14

More than 5 years have passed since last update.

AWS Amplifyのログイントークン保存先をsessionStorageに変更する

Last updated at Posted at 2018-11-08

AWS Amplifyを使って認証機能を実装したアプリケーションで、タブを閉じるごとにユーザをログアウトさせたい場合の設定

Amplify.configure

AWS Amplifyの設定初期化時に、Auth -> storage にsessionStorageを指定。

import Amplify from 'aws-amplify';

Amplify.configure({
    Auth: {
        identityPoolId: 'XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab',
        region: 'XX-XXXX-X',
        identityPoolRegion: 'XX-XXXX-X',
        userPoolId: 'XX-XXXX-X_abcd1234',

        // OPTIONAL - customized storage object
        storage: window.sessionStorage,
    }
});

※ 今回はsessionStorage設定したが、localStorage、sessionStorageと互換性があるインターフェースを持った独自のオンメモリストアclassを指定することもできそう

確認

devtools上でも、cognitoのログイントークンがsessionStorageに保存されていることが確認できた。
スクリーンショット 2018-11-09 2.58.55.png

参考

18
14
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
18
14