2

I do not know how to configure the checkbox with Vue so that it can choose to remember the username and password.

Can someone explain to me how to let Vue remember the username and password and explain to me how the solution works?

Any help is welcome

           <form>
            <div class="field">
              <div>
                <input class="input" name="username" id="username" type="text" v-model="user.username"
                       placeholder="Username">
                <!--<div class="has-text-danger">{{ usernameMessage }}</div>-->
              </div>
            </div>
            <div class="field">
              <div>
                <input class="input" name="password" id="password" type="password" v-model="user.password"
                       placeholder="Password">
                <!--<div class="has-text-danger">{{ passwordMessage }}</div>-->
              </div>
            </div>
            <div class="field">
              <label for="checkbox">First name:</label>
              <input type="checkbox" id="checkbox" @click="remember_me">
              Remember me
            </div>
            <button class="button is-info is-fullwidth" type="submit" value="Submit" @click="login">Login</button>
            <p>Not registered? <a @click="linkRegister">Create an account</a></p>
          </form>

My Vue:

<script>
import axios from 'axios'

export default {
name: 'Login',
data () {
return {
  user: {
    username: null,
    password: null
  },
  remember_me: true
}
},
methods: {
login: function () {
  var vm = this
  console.log('logging in...')
  axios.get('http://localhost:8080', {
    params: {
      username: vm.user.username,
      password: vm.user.password
    }
  }).then((result) => {
    console.log(result)
    this.$router.push({ name: 'bank_accounts' })
  }).catch((error) => {
    console.log(error)
  })
},
linkRegister: function () {
  this.$router.push({name: 'register'})
},
remember: function () {
  if (this.remember_me = true) {

  }
}
}
}
</script>
Michael Hutter
  • 1,064
  • 13
  • 33
Axel
  • 81
  • 2
  • 9
  • 6
    Most of the remembering functionality would happen by persisting a session for the user using your server-side code. You don't ever "remember" their password in Vue. You also don't want to use a GET request to log in as that can expose credentials. Careful with those bank accounts! – Jeff May 16 '18 at 20:40
  • Question is 2 years old ... I am now encountering the same dilemna. My auto-login currently works (not offering a checkbox, but I am remembering JWT in cookie). However, I want to *not* attempt an auto-login if there is no current cookie or credentials. Working through that particular issue here: [Axios: How to check for cookie in browser before sending API request?](https://stackoverflow.com/questions/63246371/axios-how-to-check-for-cookie-in-browser-before-sending-api-request) – generic3892372 Aug 04 '20 at 14:04
  • You can just use an interceptor that runs on request and check cookie if jwt token is still valid or not and then send request if valid. PS. not sure if I understand correctly but this answer according to what I understand. – Sparks Nov 29 '20 at 03:24

0 Answers0