2018-08-17 05:49:06 +00:00
|
|
|
<template>
|
|
|
|
<div class="container">
|
2018-08-17 06:29:58 +00:00
|
|
|
<h1>Sign in to access the secret page</h1>
|
2018-08-17 05:49:06 +00:00
|
|
|
<div>
|
|
|
|
<label for="email">
|
|
|
|
<input id="email" type="email" value="test">
|
|
|
|
</label>
|
|
|
|
<label for="password">
|
|
|
|
<input id="password" type="password" value="test">
|
|
|
|
</label>
|
|
|
|
<button @click="postLogin">login</button>
|
2018-09-20 09:15:16 +00:00
|
|
|
<p>The credentials are not verified for the example purpose.</p>
|
2018-08-17 05:49:06 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2018-09-19 09:00:23 +00:00
|
|
|
const Cookie = process.client ? require('js-cookie') : undefined
|
2018-08-17 05:49:06 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
middleware: 'notAuthenticated',
|
|
|
|
methods: {
|
|
|
|
postLogin() {
|
|
|
|
setTimeout(() => { // we simulate the async request with timeout.
|
|
|
|
const auth = {
|
|
|
|
accessToken: 'someStringGotFromApiServiceWithAjax'
|
|
|
|
}
|
2018-08-17 06:29:58 +00:00
|
|
|
this.$store.commit('setAuth', auth) // mutating to store for client rendering
|
2018-08-17 05:49:06 +00:00
|
|
|
Cookie.set('auth', auth) // saving token in cookie for server rendering
|
|
|
|
this.$router.push('/')
|
|
|
|
}, 1000)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|