[Vuejs]-How to add authentication persistence to Vue.js AWS-amplify app

0👍

Based on the awsamplify documentation you can use a function called onAuthUIStateChanged which can be called upon creation to check the AuthState if it is "signedIn" then simply push the router to the home view. This would be the function in the Login.Vue view.

import { AuthState, onAuthUIStateChange } from '@aws-amplify/ui-components`;

export default {
  name: 'Login',
  created() {
    onAuthUIStateChange((nextAuthState, authData) => {
      if (nextAuthState === AuthStatus.SignedIn) {
          console.log('user successfully signed in!');
          this.$router.push('/profile');
        }
      if (!authData) { console.log('user is not signed in');
        }
     });
   }

Leave a comment