Skip to content

Instantly share code, notes, and snippets.

@considine
Created August 24, 2018 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save considine/e30eb40691069d261f951c2a0bad6d46 to your computer and use it in GitHub Desktop.
Save considine/e30eb40691069d261f951c2a0bad6d46 to your computer and use it in GitHub Desktop.
finish step 8
// Your corresponding keys
Parse.initialize("YOUR_APP_ID", "YOUR_JAVASCRIPT_KEY");
// For back4app applications, this url is
// 'https://parseapi.back4app.com'
Parse.serverURL = 'YOUR_SERVER_URL'
const LoginComponent = Vue.component('login-component', {
template: '<div class="signin-wrapper text-center"> \
<form class="form-signin"> \
<h1 class="h3 mb-3 font-weight-normal">Please sign in</h1> \
<label for="inputEmail" class="sr-only">Email address</label> \
<input v-model="email" type="email" id="inputEmail" class="form-control" placeholder="Email address" required="" autofocus=""> \
<label for="inputPassword" class="sr-only">Password</label> \
<input v-model="password" type="password" id="inputPassword" class="form-control" placeholder="Password" required=""> \
<button v-on:click="login" class="btn btn-lg btn-primary btn-block" type="button">Sign in</button> \
<p class="mt-5 mb-3 text-muted">© 2017-2018</p> \
</form> \
</div>',
data : function () {
return {
email : "",
password : ""
}
},
methods : {
login () {
if (this.email.length === 0) {
alert("Please enter an email");
return;
}
if (this.password.length === 0) {
alert("Please enter a password");
return;
}
Parse.User.logIn(this.email, this.password)
.then(() => {
// Used an arrow function here because I
// want to access 'this' which is overridden in
// a conventional function
this.$router.replace("/");
})
.catch(function(e) {
alert ("Error logging in! " + e.message);
});
}
}
})
const HomeComponent = Vue.component("home-component", {
template : "<div> \
<h1> Hello World! </h1> \
</div>",
mounted : function () {
if (!Parse.User.current()) {
this.$router.replace("/login");
}
}
})
const app = new Vue({
router
}).$mount('#app')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment