Difference between revisions of "User:Saul/feathers"

From Organic Design wiki
(Usage)
m (Client Authentication)
Line 50: Line 50:
 
== Client Authentication ==
 
== Client Authentication ==
 
I had an issue where the client authenticated and I received the authentication token but when I use a service it says that I'm not authenticated.<br>
 
I had an issue where the client authenticated and I received the authentication token but when I use a service it says that I'm not authenticated.<br>
The solution was to ensure that the client setup that transport before the authentication.
+
The solution was to ensure that the client setup the transport before the authentication.

Revision as of 20:34, 9 August 2018

Feathers is a lightweight framework for setting up REST API's and realtime events.

Install

CLI

Install the cli to get started with you feathers application quickly.

npm install -g @feathersjs/cli

App

To get feathers to generate the app run:

feathers generate app

Authentication

To generate a authentication method use:

feathers generate authentication

Services

Services are a way to set up the REST API for a service like messages, users, channels, ect.

feathers generate service

Hooks

To generate a hook via the command line run:

feathers generate hook

Setup

TBC

Usage

Reverse Pagination

The best way that I have found to get the latest objects in the database is to use $sort like so:

app.service("messages").find({
	query: {
		$limit: 10,
		$sort: {
			createdAt: -1
		}
	}
}).then(res => {
	const latestData = res.data.reverse();
};

Manipulating MongoDB Arrays

https://docs.mongodb.com/manual/reference/operator/update-array/

Troubleshooting

Client Authentication

I had an issue where the client authenticated and I received the authentication token but when I use a service it says that I'm not authenticated.
The solution was to ensure that the client setup the transport before the authentication.