An open API service indexing awesome lists of open source software.

https://github.com/nigeltiany/email-auth


https://github.com/nigeltiany/email-auth

Last synced: 3 months ago
JSON representation

Awesome Lists containing this project

README

        

[Firebase](https://firebase.google.com/docs/web/setup) for [VueJS](https://vuejs.org/) -- email-auth plugin.
For Use with [VueFire](https://github.com/nigeltiany/vuefire) integration

## Install

```bash
npm install @vuefire/vuefire --save
npm install @vuefire/email-auth --save
```

## Usage
#### Configuration
```js
import VueFire from '@vuefire/vuefire'
import VueFire_Email_Auth from '@vuefire/email-auth'

Vue.use(VueFire, {
project: {
apiKey: "",
authDomain: ".firebaseapp.com",
databaseURL: "https://.firebaseio.com",
storageBucket: ".appspot.com",
messagingSenderId: "",
projectId: '',
},
mixins: [VueFire_Email_Auth]
})

// in components
this.$firebase.emailSignIn('', '').then(
(user) => {
},
(error) => {
}
);
// Or
this.$firebase.emailSignIn('', '',{ mutate: "vuexMutation" }).catch((error) => {

});
// Or a namespaced mutation : /mutationName
this.$firebase.emailSignIn('', '',{ mutate: "authentication/vuexMutation" }).catch((error) => {

});
// Or
this.$firebase.emailSignIn('', '', function(error, user) {

})

//Signing user up
this.$firebase.emailSignUp('', '').then(
(user) => {
},
(error) => {
}
);
// Or
this.$firebase.emailSignUp('', '',{ mutate: "vuexMutation" }).catch((error) => {

});
// Or
this.$firebase.emailSignUp('', '', function(error, user) {

})
```

### Vuex Usage

```js
Vue.use(VueFire, {
project: {
apiKey: "",
authDomain: ".firebaseapp.com",
databaseURL: "https://.firebaseio.com",
storageBucket: ".appspot.com",
messagingSenderId: "",
projectId: '',
},
mixins: [{
vuex: true,
sources: [VueFire_Email_Auth]
}]
})

// In components
export default {
data () {
return {
user: {
email: null,
password: null,
// Mutation to commit when/if login/signup is successful
mutate: 'authentication/authenticatedUser',
// Firebase path to save user. Defaults to 'users/'
firebasePath: 'users/',
// Function to call on validation error
error: this.error
}
}
},
methods: {
...mapActions('authentication', [
'emailSignUp',
'emailSignIn'
]),
error (error) {
// console.log(error)
// Or show toast message
}
}
}

// Vuex example
export default {

namespaced: true,

state: {
user: JSON.parse(localStorage.getItem('user')) || {}
},

getters: {
authUser (state) {
return state.user
}
},

mutations: {
authenticatedUser (state, authenticatedUser) {
Object.assign(state.user, authenticatedUser)
router.push({ path: '/' })
localStorage.setItem('user', JSON.stringify(authenticatedUser))
}
}
}
```

See [VueFire](https://github.com/nigeltiany/vuefire) Package Documentation on how to use mixins