Skip to content
Update Documentation authored by Felix Cervin's avatar Felix Cervin
# Feathers
#### Changes in behavior
With the initial setup of Feathers JS, it is possible to create users via the REST service. **This has been disabled for this boilerplate.** If you want to be able to create users via, for example, Postman, please adjust this code (which can be found in *src/services/users/users.service.js*):
```javascript
// A bit of custom validation, before anything is stored/sent to the server.
service.hooks({
before: {
create( context ) {
// If the provider is not from socketio, then throw an error. Disallow creation of accounts from outside the website.
if( context.params.provider !== 'socketio' ) {
throw new Error('Unfortunately, we don\'t offer account creation externally. Please, create the account on our website.')
// Do a simple regex test of the password.
} else if( !passwordRegex.test( context.arguments[0].password ) ) {
throw new Error('Invalid password. Passwords has to contain between 6 - 64 characters, include a upper- and lowercase letter, a number and a symbol. ASCII characters are strictly forbidden.')
}
}
}
})
```
#### Vue.app
**Information:**
*Vue.app is the Feathers instance. As in:*
......@@ -15,6 +43,7 @@ Vue.app = Vue.feathers()
Vue.app.emit('error', 'This is an error message.')
Vue.app.service('users').create({...})
```
**Side note:** `Vue.app.emit('error', 'Message...')` triggers VueNotifications.
You also have access to the Feathers Socket. Here's how it's setup:
```javascript
......@@ -29,4 +58,56 @@ Vue.socket = Vue.io('http://localhost:3030')
```javascript
Vue.socket.emit('authenticate', { ... })
Vue.socket.emit('find', 'users', ...)
```
### Feathers Logger
*Feathers comes with [winstonjs/winston](https://github.com/winstonjs/winston), a.k.a, Logger. This is also bound to the Vue instance, and triggers the VueNotifications:*
```javascript
Vue.Logger('error', 'This is an error.')
Vue.Logger('warn', 'This is a warning.')
Vue.Logger('info', 'This is some information.')
...
```
### Notification options
> error
> warn
> info
> success
**Examples:**
```javascript
Vue.app.emit('error', 'Here\'s an error notification.')
Vue.app.emit('info', 'Here'\s an information notification.')
```
*If you want to only log to console, just use `console.log`*
You can find the following code in `~/layouts/default.vue`:
```javascript
// Listen to all errors, warnings, info and success events.
created: function() {
Vue.app.on('error', (message) => {
this.error({ title: 'Error', message: message, type: 'error' })
})
Vue.app.on('warn', (message) => {
this.warn({ title: 'Warning', message: message, type: 'warn' })
})
Vue.app.on('info', (message) => {
this.info({ title: 'Info', message: message, type: 'info' })
})
Vue.app.on('success', (message) => {
this.success({ title: 'Success', message: message, type: 'success' })
})
},
```
\ No newline at end of file