2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

そうだ、永続的にログイン状態を保持する機能を付けよう

Posted at

リロードするたびにログインする

そんな負担ユーザーには掛けられないですよね???

今回はそんなお悩みを、読み終わったときには、「こんなに簡単なんだ!」って思うくらい簡単に説明します!(モジュールをインストールして、プラグインするだけ)

モジュールのインストール#

以下のコマンドを入力し、モジュールをインストールします。

npm install vuex-persistedstate
yarn

プラグイン#

ユーザー認証を行っているファイル(今回はstore/index.js)にて行います。

store/index.js

import Vue from "vue";
import Vuex from "vuex";
import createPersistedState from "vuex-persistedstate";  
//モジュールをインポートします

Vue.use(Vuex);

export default new Vuex.Store({
  plugins: [createPersistedState()],  //プラグイン
  state: {
    auth: true,  //ユーザーがログインしているか
    user: "",    //ユーザー情報
  },
});

これでauthのtrue(ログイン)状態が保持されます。

こんなに簡単です!!

以上、永続的にログイン状態を保持する方法でした!

良かったら、LGTM、コメントお待ちしております。

また、何か間違っていることがあればご指摘頂けると幸いです。

Thank you for reading

2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?