Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.

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

参考

https://aws-amplify.github.io/docs/js/authentication

https://github.com/aws-amplify/amplify-js/issues/925

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away