mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-05 21:53:56 +00:00
36 lines
1002 B
Vue
36 lines
1002 B
Vue
<template>
|
|
<div class="container">
|
|
<h1>Sign in to access the secret page</h1>
|
|
<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>
|
|
<p>The crendentials are not verified for the example purpose.</p>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
const Cookie = process.browser ? require('js-cookie') : undefined
|
|
|
|
export default {
|
|
middleware: 'notAuthenticated',
|
|
methods: {
|
|
postLogin() {
|
|
setTimeout(() => { // we simulate the async request with timeout.
|
|
const auth = {
|
|
accessToken: 'someStringGotFromApiServiceWithAjax'
|
|
}
|
|
this.$store.commit('setAuth', auth) // mutating to store for client rendering
|
|
Cookie.set('auth', auth) // saving token in cookie for server rendering
|
|
this.$router.push('/')
|
|
}, 1000)
|
|
}
|
|
}
|
|
}
|
|
</script>
|