Skip to content

Commit

Permalink
📦 Update dependency auth module
Browse files Browse the repository at this point in the history
  • Loading branch information
cesaramirez committed Feb 10, 2018
1 parent 7a0f1d0 commit 14d7501
Show file tree
Hide file tree
Showing 9 changed files with 305 additions and 596 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ dist

# PWA
sw.*

.vscode
.DS_Store
14 changes: 3 additions & 11 deletions components/NavBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
</router-link>
</v-toolbar-title>
<v-spacer></v-spacer>
<template v-if="user">
<template v-if="$auth.state.user">
<v-btn flat :to="{ name: 'home' }" nuxt>
Home
</v-btn>
<v-btn flat>
{{ user.name }}
{{ $auth.state.user.name }}
</v-btn>
</template>
<v-tooltip bottom>
Expand All @@ -28,17 +28,9 @@
<script>
import { mapState } from 'vuex'
export default {
computed: mapState({
user: state => state.auth.user
}),
methods: {
logout () {
this.$store.dispatch('auth/logout')
.then(() => {
this.$router.replace({
name: 'auth-login'
})
})
this.$auth.logout()
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion layouts/Auth.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

<script>
export default {
middleware: 'no-auth',
middleware: ['auth'],
options: {
auth: false
},
transition (to, from) {
// Access component properties here
console.log(to.matched[0].components.default.options)
Expand Down
3 changes: 1 addition & 2 deletions layouts/default.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<v-app>
<navbar></navbar>
<navbar v-if=""></navbar>
<notification></notification>
<v-content>
<v-container fluid>
Expand All @@ -15,7 +15,6 @@
import Navbar from '@/components/NavBar.vue'
import Notification from '@/components/Notification.vue'
export default {
middleware: 'auth',
components: {
Navbar,
Notification
Expand Down
37 changes: 12 additions & 25 deletions nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,22 @@ module.exports = {

modules: [
'@nuxtjs/auth',
'@nuxtjs/axios',
'@nuxtjs/pwa'
'@nuxtjs/axios'
],

router: {
middleware: ['auth']
},

auth: {
user: {
endpoint: 'http://vue.laravel.starter.app/api/v1/auth/me',
propertyName: '',
resetOnFail: false,
enabled: true,
method: 'POST'
},
login: {
endpoint: 'http://vue.laravel.starter.app/api/v1/auth/login'
},
logout: {
endpoint: 'http://vue.laravel.starter.app/api/v1/auth/logout',
method: 'POST'
endpoints: {
login: { url: 'http://vue.laravel.starter.test/api/v1/auth/login', method: 'post', propertyName: 'token' },
logout: { url: 'http://vue.laravel.starter.test/api/v1/auth/logout', method: 'post' },
user: { url: 'http://vue.laravel.starter.test/api/v1/auth/me', method: 'post', propertyName: false }
},
redirect: {
notLoggedIn: '/auth/login',
loggedIn: '/'
},
token: {
enabled: true,
type: 'Bearer',
localStorage: false,
name: 'token',
cookie: true,
cookieName: 'token'
login: '/auth/login',
home: '/home'
}
},

Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
"generate": "nuxt generate"
},
"dependencies": {
"@nuxtjs/auth": "^3.4.1",
"@nuxtjs/axios": "^4.5.0",
"@nuxtjs/pwa": "^2.0.5",
"@nuxtjs/auth": "^4.0.0-rc.3",
"@nuxtjs/axios": "^5.0.1",
"lodash": "^4.17.4",
"nuxt": "^1.1.1",
"nuxt": "^1.3.0",
"vee-validate": "^2.0.0",
"vuetify": "^0.17.4"
},
Expand Down
161 changes: 66 additions & 95 deletions pages/auth/Login.vue
Original file line number Diff line number Diff line change
@@ -1,106 +1,77 @@
<template>
<v-layout align-center justify-center>
<v-flex xs12 sm8 md6 lg4>
<v-card>
<v-card-title primary-title>
<v-flex justify-center hidden-sm-and-down>
<img src="/logo.png" alt="Logo" height="150px" class="text-xs-center" style="display: block; margin: 0 auto;">
<h1 class="headline text-xs-center">Log In</h1>
</v-flex>
<v-flex justify-center hidden-md-and-up>
<h1 class="headline text-xs-center">Log In</h1>
</v-flex>
</v-card-title>
<v-form @submit.prevent="submit">
<v-card-text>
<v-layout row>
<v-flex xs12>
<v-text-field
v-model="form.email"
name="email"
label="Email"
prepend-icon="mail"
:error-messages="errors.collect('email')"
v-validate="'required|email'"
data-vv-name="email"
></v-text-field>
</v-flex>
</v-layout>
<v-layout row>
<v-flex xs12>
<v-text-field
v-model="form.password"
name="password"
label="Password"
type="password"
prepend-icon="vpn_key"
:error-messages="errors.collect('password')"
v-validate="'required|min:6'"
data-vv-name="password"
></v-text-field>
</v-flex>
</v-layout>
</v-card-text>
<v-card-actions>
<v-layout row wrap>
<v-flex xs12 lg6>
<v-btn type="submit" color="primary" block :loading="loading">Log In</v-btn>
</v-flex>
<v-flex xs12 lg6>
<v-btn flat :to="{ name: 'forgot' }" color="primary" block>Forgot Your Password?</v-btn>
</v-flex>
</v-layout>
</v-card-actions>
</v-form>
</v-card>
</v-flex>
</v-layout>
<v-layout align-center justify-center>
<v-flex xs12 sm8 md6 lg4>
<v-card>
<v-card-title primary-title>
<v-flex justify-center hidden-sm-and-down>
<img src="/logo.png" alt="Logo" height="150px" class="text-xs-center" style="display: block; margin: 0 auto;">
<h1 class="headline text-xs-center">Log In</h1>
</v-flex>
<v-flex justify-center hidden-md-and-up>
<h1 class="headline text-xs-center">Log In</h1>
</v-flex>
</v-card-title>
<v-form @submit.prevent="submit">
<v-card-text>
<v-layout row>
<v-flex xs12>
<v-text-field v-model="form.email" name="email" label="Email" prepend-icon="mail" :error-messages="errors.collect('email')"
v-validate="'required|email'" data-vv-name="email"></v-text-field>
</v-flex>
</v-layout>
<v-layout row>
<v-flex xs12>
<v-text-field v-model="form.password" name="password" label="Password" type="password" prepend-icon="vpn_key" :error-messages="errors.collect('password')"
v-validate="'required|min:6'" data-vv-name="password"></v-text-field>
</v-flex>
</v-layout>
</v-card-text>
<v-card-actions>
<v-layout row wrap>
<v-flex xs12>
<v-btn type="submit" color="primary" block :loading="loading">Log In</v-btn>
</v-flex>
</v-layout>
</v-card-actions>
</v-form>
</v-card>
</v-flex>
</v-layout>
</template>

<script>
import { mapActions } from 'vuex'
import _ from 'lodash'
export default {
layout: 'auth',
data () {
return {
form: {
email: '',
password: ''
},
loading: false
}
},
methods: {
...mapActions({
login: 'auth/login'
}),
submit () {
this.$validator.validateAll().then(result => {
if (result) {
this.loading = true
this.login({
fields: {
email: this.form.email,
password: this.form.password
}
}).then(() => {
this.loading = false
this.$store.dispatch('noti', { message: 'You are Log In!', type: 'success' })
return this.$router.push({ path: '/' })
}).catch((e) => {
this.loading = false
_.forEach(e.response.data.errors, (value, key) => {
this.errors.add(key, value[0])
})
})
}
})
}
import _ from "lodash";
export default {
layout: "auth",
middlare: false,
data() {
return {
form: {
email: "",
password: ""
},
loading: false
};
},
methods: {
submit() {
this.$validator.validateAll().then(result => {
if (result) {
this.$auth.login({
data: {
email: this.form.email,
password: this.form.password
}
});
}
});
}
}
};
</script>

<style scoped>
</style>
6 changes: 6 additions & 0 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@
</v-flex>
</v-layout>
</template>

<script>
export default {
middleware: ['auth'],
}
</script>
Loading

0 comments on commit 14d7501

Please sign in to comment.