Note: This plugin ships with and should be used with
axios
andparse-server
plugins
1 Clone this repo https://github.com/dare-mcadewole/nuxt-plugins.git
2 Make sure the Auth
folder, axios.js
and parse-server.js
are in Nuxt's plugin
directory
3 Add the axios
, parse-server
and Auth
plugin to the plugin
array in nuxt.config.js
(in this same order) i.e.
{
...
plugins: [
...
'~/plugins/axios',
'~/plugins/parse-server',
'~/plugins/Auth',
...
],
...
}
4 Edit the config
constant in parse-server.js
to suit your Parse APP details:
const config = {
appId: '<PARSE-APP-ID>',
restApiKey: '<PARSE-REST-API-KEY>',
serverURL: '<PARSE-SERVER-URL>',
clientKey: '<PARSE-CLIENT-KEY>',
masterKey: '<PARSE-MASTER-KEY>'
}
You can use this.$user
to access any of the following methods:
ALL METHODS RETURN Promises
Method: create
Parameter: user
(object)
this.$user.create({
name: 'John Doe',
email: 'john@doe.com',
password: 'blahblahblah'
}).then((response) => {}).catch(err => {})
Method: authenticate
Parameter: username
(string) and password
(string)
this.$user.authenticate('John_Doe', 'blahblahblah')
.then((response) => {}).catch(err => {})
Method: get
Parameter: objectId
(string)
this.$user.get('5fsstgy7').then((response) => {}).catch(err => {})
Method: getAll
Parameter: None
this.$user.getAll().then((response) => {}).catch(err => {})
Method: update
Parameter: An Object{} that contains token
(string), objectId
(string) and data
(object)
this.$user.update({
token: '<USER_TOKEN>',
objectId: '<OBJECT_ID>',
data: {
name: 'Doe John'
}
})
.then((response) => {}).catch(err => {})
Method: validateSession
Parameter: token
(string)
this.$user.validateSession('<USER_TOKEN>')
.then((response) => {}).catch(err => {})
Method: resetPassword
Parameter: email
(string)
this.$user.resetPassword('john@doe.com')
.then((response) => {}).catch(err => {})
You can
-
Use
this.$http
to do API calls the normal way you would withaxios
this.$http.get('https://www.restapi.com/data').then().catch()
-
Use
this.$parseapi
to ease API calls to Parse Server. e.g. To access other classes:this.$parseapi.get('/classes/<Class>').then().catch()
Method: create
Parameter: className
(string) and data
(object)
this.$objs.create('Category', {
foo: 'bar',
name: 'kettle',
lang: 'Ibo'
})
.then((response) => {})
.catch(err => {})
Method: read
Parameter: className
(string) and objectId
(string)
this.$objs.read('Categories', 'xxYIgdj7')
.then((response) => {})
.catch(err => {})
Method: readAll
Parameter: className
(string)
this.$objs.get('Categories')
.then((response) => {})
.catch(err => {})
Method: update
Parameter: className
(string), objectId
(string) and data
(object)
this.$objs.update({
className: 'Categories',
objectId: 'xxNmIJk5',
data: {
foo: 'bar',
name: 'Doe John',
lang: 'Yoruba'
}
})
.then((response) => {})
.catch(err => {})
Method: delete
Parameter: className
(string) and objectId
this.$objs.delete('xxYYNUI4')
.then((response) => {})
.catch(err => {})
#👏 Dare MCAdewole
Adjusted by: Ukwuani Barnabas