Skip to content

Commit bb6fade

Browse files
authored
1 parent f13844c commit bb6fade

File tree

19 files changed

+213
-78
lines changed

19 files changed

+213
-78
lines changed

.vuepress/config.js

+3
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ module.exports = {
113113
items: [{
114114
text: 'Awesome Feathersjs',
115115
link: 'https://github.com/feathersjs/awesome-feathersjs'
116+
}, {
117+
text: 'YouTube Playlist',
118+
link: 'https://www.youtube.com/playlist?list=PLwSdIiqnDlf_lb5y1liQK2OW5daXYgKOe'
116119
}, {
117120
text: 'Previous versions',
118121
items: [{

.vuepress/public/_redirects

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# https://crow.docs.feathersjs.com/* https://docs.feathersjs.com/:splat 301!
1+
https://crow.docs.feathersjs.com/* https://docs.feathersjs.com/:splat 301!
22

33
# v2 Redirects
44

.vuepress/styles/index.styl

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
@require '~vuepress-plugin-tabs/dist/themes/default.styl'
2-
@import 'https://fonts.googleapis.com/css?family=Raleway&display=swap.css';
2+
@import 'https://fonts.googleapis.com/css?family=Raleway&display=swap.css';
3+
@import 'https://fonts.googleapis.com/css?family=Lato&display=swap.css'

.vuepress/theme/styles/index.styl

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ html, body
1010
background-color #fff
1111

1212
body
13-
font-family 'Raleway', 'Helvetica Neue', 'Helvetica', 'Arial', 'Lucida Grande', sans-serif
13+
font-family 'Lato', 'Helvetica Neue', 'Helvetica', 'Arial', 'Lucida Grande', sans-serif
1414
-webkit-font-smoothing antialiased
1515
-moz-osx-font-smoothing grayscale
1616
font-size 16px
@@ -20,6 +20,7 @@ body
2020
padding-left $sidebarWidth
2121

2222
.navbar
23+
font-family 'Raleway', 'Helvetica Neue', 'Helvetica', 'Arial', 'Lucida Grande', sans-serif
2324
position fixed
2425
z-index 20
2526
top 0
@@ -40,6 +41,7 @@ body
4041
display none
4142

4243
.sidebar
44+
font-family 'Raleway', 'Helvetica Neue', 'Helvetica', 'Arial', 'Lucida Grande', sans-serif
4345
font-size 16px
4446
background-color #fff
4547
width $sidebarWidth
@@ -104,6 +106,7 @@ strong
104106
font-weight 600
105107

106108
h1, h2, h3, h4, h5, h6
109+
font-family 'Raleway', 'Helvetica Neue', 'Helvetica', 'Arial', 'Lucida Grande', sans-serif
107110
font-weight 600
108111
line-height 1.25
109112
.content:not(.custom) > &

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ Welcome to the FeathersJS documentation! Feathers is a web-framework for creatin
1111

1212
At its core, Feathers is a set of tools and an architecture pattern that make it easy to create scalable REST APIs and real-time applications. You can build prototypes in minutes and production-ready apps in days. To get started, follow one of the following links:
1313

14-
[__Read the guide to learn more and get started with Feathers >__](./guides/readme.md)
14+
[The Feathers guide >](./guides/readme.md)
1515

16-
[__Dig into the API documentation >__](./api/readme.md)
16+
[The API documentation >](./api/readme.md)
1717

18-
[__Check out the cookbook for common tasks and patterns >__](./cookbook/readme.md)
18+
[The cookbook for common tasks and patterns >](./cookbook/readme.md)
1919

20-
[__Have a look at frequently asked questions and other ways to get help >__](./help/readme.md)
20+
[FAQ and ways to get help >](./help/readme.md)
2121

22-
[__Migrate to the latest version >__](./guides/migrating.md)
22+
[Migrate to the latest version >](./guides/migrating.md)

api/assets/architecture-overview.svg

+1
Loading

api/authentication/client.md

+4
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ Returns the instance of the [AuthenticationClient](#authenticationclient).
126126

127127
`app.authentication.reset()` resets the authentication state without explicitly logging out. Should not be called directly.
128128

129+
### handleError()
130+
131+
`app.authentication.handleError(error, type: 'authenticate'|'logout') -> Promise` handles any error happening in the `authenticate` or `logout` method. By default it removes the access token if the error is a `NotAuthenticate` error. Otherwise it does nothing.
132+
129133
### reAuthenticate(force)
130134

131135
`app.authentication.reAuthenticate(force = false) -> Promise` will re-authenticate with the current access token from [app.authentication.getAccessToken()](). If `force` is set to `true` it will always reauthenticate, with the default `false` only when not already authenticated.

api/authentication/oauth.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ To _link an existing user_ the current access token can be added the oAuth flow
9797
</a>
9898
```
9999

100-
This will use the user (entity) of that access token to link the oAuth account to.
100+
This will use the user (entity) of that access token to link the oAuth account to. Using the [authentication client](./client.md) you can get the current access token via `app.get('authentication')`:
101+
102+
```js
103+
const { accessToken } = await app.get('authentication');
104+
```
101105

102106
### Redirects
103107

@@ -113,11 +117,11 @@ The `redirect` configuration option is used to redirect back to the frontend app
113117
}
114118
```
115119

116-
Will redirect to `https://app.mydomain.com/#access_token=<user jwt>` or `https://app.mydomain.com/#error=<some error message>`. The [authentication client](./client.md) handles those redirect automatically. It can be customized with the [getRedirect()](#getredirect) method of the oAuth strategy.
120+
Will redirect to `https://app.mydomain.com/#access_token=<user jwt>` or `https://app.mydomain.com/#error=<some error message>`. Redirects can be customized with the [getRedirect()](#getredirect) method of the oAuth strategy. The [authentication client](./client.md) handles the default redirects automatically already.
117121

118-
> __Note:__ The redirect is using a hash instead of a query string by default because it is not logged server side and can be easily manipulated on the client.
122+
> __Note:__ The redirect is using a hash instead of a query string by default because it is not logged server side and can be easily read on the client.
119123
120-
If `redirect` option is not set, the authentication result data will be sent as JSON instead.
124+
If the `redirect` option is not set, the authentication result data will be sent as JSON instead.
121125

122126
## Setup (Express)
123127

api/client/rest.md

+6
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ POST /messages
286286
]
287287
```
288288

289+
> **Note:** With a [database adapters](../databases/adapters.md) the [`multi` option](./databases/common.md) has to be set explicitly to support creating multiple entries.
290+
289291
### update
290292

291293
Completely replace a single or multiple resources.
@@ -324,6 +326,8 @@ PATCH /messages?complete=false
324326

325327
Will call `messages.patch(null, { complete: true }, { query: { complete: 'false' } })` on the server to change the status for all read messages.
326328

329+
> **Note:** With a [database adapters](../databases/adapters.md) the [`multi` option](./databases/common.md) has to be set to support patching multiple entries.
330+
327331
This is supported out of the box by the Feathers [database adapters](../databases/adapters.md)
328332

329333
### remove
@@ -343,3 +347,5 @@ DELETE /messages?read=true
343347
```
344348

345349
Will call `messages.remove(null, { query: { read: 'true' } })` to delete all read messages.
350+
351+
> **Note:** With a [database adapters](../databases/adapters.md) the [`multi` option](./databases/common.md) has to be set to support patching multiple entries.

api/readme.md

+52-26
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,58 @@
11
# API
22

3-
This section describes all the APIs of Feathers and its individual modules.
4-
5-
* __Core:__ Feathers core functionality
6-
* [Application](application.md) - The main Feathers application API
7-
* [Services](services.md) - Service objects and their methods and Feathers specific functionality
8-
* [Hooks](hooks.md) - Pluggable middleware for service methods
9-
* [Events](events.md) - Events sent by Feathers service methods
10-
* [Errors](errors.md) - A collection of error classes used throughout Feathers
11-
* [Configuration](configuration.md) - A node-config wrapper to initialize configuration of a server side application.
12-
* __Transports:__ Expose a Feathers application as an API server
3+
This section describes all the individual modules and APIs of Feathers. There are three main sections of the API:
4+
5+
- __Core:__ The Feathers core functionality that can be used on the server and the client
6+
- __Server:__ Feathers server side modules used with Core when creating an API server in NodeJS
7+
- __Client:__ Modules used on the client (NodeJS, browser or React Native) together with Core when connecting to a Feathers API server.
8+
9+
Here is an overview how the individual sections of the API documentation fit together:
10+
11+
![Feathers Architecture overview](./assets/architecture-overview.svg)
12+
13+
## Core
14+
15+
Feathers core functionality that works on the client and the server
16+
17+
* [Application](application.md) - The main Feathers application API
18+
* [Services](services.md) - Service objects and their methods and Feathers specific functionality
19+
* [Hooks](hooks.md) - Pluggable middleware for service methods
20+
* [Events](events.md) - Events sent by Feathers service methods
21+
* [Errors](errors.md) - A collection of error classes used throughout Feathers
22+
23+
## Transports
24+
25+
Expose a Feathers application as an API server
1326
* [Express](express.md) - Feathers Express framework bindings, REST API provider and error middleware.
1427
* [Socket.io](socketio.md) - The Socket.io real-time transport provider
1528
* [Primus](primus.md) - The Primus real-time transport provider
29+
* [Configuration](configuration.md) - A node-config wrapper to initialize configuration of a server side application.
1630
* [Channels](channels.md) - Decide what events to send to connected real-time clients
17-
* __Client:__ More details on how to use Feathers on the client
18-
* [Usage](client.md) - Feathers client usage in Node, React Native and the browser (also with Webpack and Browserify)
19-
* [REST](client/rest.md) - Feathers client and direct REST API server usage
20-
* [Socket.io](client/socketio.md) - Feathers client and direct Socket.io API server usage
21-
* [Primus](client/primus.md) - Feathers client and direct Primus API server usage
22-
* __Authentication:__ Feathers authentication mechanism
23-
* [Service](authentication/service.md) - The main authentication service configuration
24-
* [Strategies](authentication/strategy.md) - More about authentication strategies
25-
* [Local](authentication/local.md) - Local email/password authentication
26-
* [JWT](authentication/jwt.md) - JWT authentication
27-
* [OAuth](authentication/oauth.md) - Using oAuth logins (Facebook, Twitter etc.)
28-
* [Client](authentication/client.md) - A client for a Feathers authentication server
29-
* __Database:__ Feathers common database adapter API and querying mechanism
30-
* [Adapters](databases/adapters.md) - A list of supported database adapters
31-
* [Common API](databases/common.md) - Database adapter common initialization and configuration API
32-
* [Querying](databases/querying.md) - The common querying mechanism
31+
32+
## Client
33+
34+
More details on how to use Feathers on the client
35+
36+
* [Usage](client.md) - Feathers client usage in Node, React Native and the browser (also with Webpack and Browserify)
37+
* [REST](client/rest.md) - Feathers client and direct REST API server usage
38+
* [Socket.io](client/socketio.md) - Feathers client and direct Socket.io API server usage
39+
* [Primus](client/primus.md) - Feathers client and direct Primus API server usage
40+
41+
## Authentication
42+
43+
Feathers authentication mechanism
44+
45+
* [Service](authentication/service.md) - The main authentication service configuration
46+
* [Strategies](authentication/strategy.md) - More about authentication strategies
47+
* [Local](authentication/local.md) - Local email/password authentication
48+
* [JWT](authentication/jwt.md) - JWT authentication
49+
* [OAuth](authentication/oauth.md) - Using oAuth logins (Facebook, Twitter etc.)
50+
* [Client](authentication/client.md) - A client for a Feathers authentication server
51+
52+
## Databases
53+
54+
Feathers common database adapter API and querying mechanism
55+
56+
* [Adapters](databases/adapters.md) - A list of supported database adapters
57+
* [Common API](databases/common.md) - Database adapter common initialization and configuration API
58+
* [Querying](databases/querying.md) - The common querying mechanism

api/services.md

+8
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,23 @@ app.use('/messages', {
158158

159159
> **Important:** A successful `create` method call emits the [`created` service event](./events.md#created).
160160
161+
> **Note:** With a [database adapters](./databases/adapters.md) `data` can be an array but the [`multi` option](./databases/common.md) has to be set.
162+
161163

162164
### .update(id, data, params)
163165

164166
`service.update(id, data, params) -> Promise` - Replaces the resource identified by `id` with `data`. The method should return with the complete, updated resource data. `id` can also be `null` when updating multiple records, with `params.query` containing the query criteria.
165167

166168
> **Important:** A successful `update` method call emits the [`updated` service event](./events.md#updated-patched).
167169
170+
> **Note:** The [database adapters](./databases/adapters.md) do not support completely replacing multiple entries.
171+
168172
### .patch(id, data, params)
169173

170174
`patch(id, data, params) -> Promise` - Merges the existing data of the resource identified by `id` with the new `data`. `id` can also be `null` indicating that multiple resources should be patched with `params.query` containing the query criteria.
171175

176+
> **Note:** With a [database adapters](./databases/adapters.md) the [`multi` option](./databases/common.md) has to be set explicitly to support patching multiple entries.
177+
172178
The method should return with the complete, updated resource data. Implement `patch` additionally (or instead of) `update` if you want to distinguish between partial and full updates and support the `PATCH` HTTP method.
173179

174180
> **Important:** A successful `patch` method call emits the [`patched` service event](./events.md#updated-patched).
@@ -180,6 +186,8 @@ The method should return with the complete, updated resource data. Implement `pa
180186

181187
> **Important:** A successful `remove` method call emits the [`removed` service event](./events.md#removed).
182188
189+
> **Note:** With a [database adapters](./databases/adapters.md) the [`multi` option](./databases/common.md) has to be set explicitly to support removing multiple entries.
190+
183191

184192
### .setup(app, path)
185193

cookbook/authentication/anonymous.md

+75-10
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,101 @@
22

33
Anonymous authentication can be allowed by creating a [custom strategy](../../api/authentication/strategy.md) that returns the `params` that you would like to use to identify an authenticated user.
44

5+
:::: tabs :options="{ useUrlFragment: false }"
6+
::: tab "JavaScript"
7+
In `src/authentication.js`:
8+
59
```js
610
const { AuthenticationBaseStrategy } = require('@feathersjs/authentication');
711

812
class AnonymousStrategy extends AuthenticationBaseStrategy {
9-
authenticate(authentication, params) {
13+
async authenticate(authentication, params) {
14+
return {
15+
anonymous: true
16+
}
17+
}
18+
}
19+
20+
module.exports = app => {
21+
// ... authentication service setup
22+
authentication.register('anonymous', new AnonymousStrategy());
23+
}
24+
```
25+
:::
26+
::: tab "TypeScript"
27+
```ts
28+
import { Params } from '@feathersjs/feathers';
29+
import { AuthenticationBaseStrategy, AuthenticationResult } from '@feathersjs/authentication';
30+
31+
class AnonymousStrategy extends AuthenticationBaseStrategy {
32+
async authenticate(authentication: AuthenticationResult, params: Params) {
1033
return {
1134
anonymous: true
1235
}
1336
}
1437
}
1538

16-
app.service('authentication').register('anonymous', new AnonymousStrategy());
39+
export default function(app: Application) {
40+
// ... authentication service setup
41+
authentication.register('anonymous', new AnonymousStrategy());
42+
}
1743
```
44+
:::
45+
::::
46+
1847

19-
Next, we need to create a hook called `allow-anonymous` that sets [params.authentication]() if it does not exist and if `params.provider` exists (which means it is an external call) to use that `anonymous` strategy:
48+
Next, we create a hook called `allow-anonymous` that sets `params.authentication` if it does not exist and if `params.provider` exists (which means it is an external call) to use that `anonymous` strategy:
2049

50+
:::: tabs :options="{ useUrlFragment: false }"
51+
::: tab "JavaScript"
2152
```js
22-
const { params } = context;
53+
/* eslint-disable require-atomic-updates */
54+
module.exports = function (options = {}) { // eslint-disable-line no-unused-vars
55+
return async context => {
56+
const { params } = context;
57+
58+
if(params.provider && !params.authentication) {
59+
context.params = {
60+
...params,
61+
authentication: {
62+
strategy: 'anonymous'
63+
}
64+
}
65+
}
66+
67+
return context;
68+
};
69+
};
70+
```
71+
:::
72+
::: tab "TypeScript"
73+
```ts
74+
import { Hook, HookContext } from '@feathersjs/feathers';
2375

24-
if(params.provider && !params.authentication) {
25-
params.authentication = {
26-
strategy: 'anonymous'
76+
export default (): Hook => {
77+
return async (context: HookContext) => {
78+
const { params } = context;
79+
80+
if(params.provider && !params.authentication) {
81+
context.params = {
82+
...params,
83+
authentication: {
84+
strategy: 'anonymous'
85+
}
86+
}
87+
}
88+
89+
return context;
2790
}
2891
}
2992
```
93+
:::
94+
::::
3095

31-
This hook should be added __before__ the [authenticate hook]() wherever anonymous authentication should be allowed:
96+
This hook should be added __before__ the [authenticate hook](../api/authentication/hook.md) wherever anonymous authentication should be allowed:
3297

33-
```
34-
all: [ allowAnonymous(), authenticate('jwt', 'anonymous') ]
98+
```js
99+
all: [ allowAnonymous(), authenticate('jwt', 'anonymous') ],
35100
```
36101

37102
If an anonymous user now accesses the service externally, the service call will succeed and have `params.anonymous` set to `true`.
-22.6 KB
Loading

guides/basics/authentication.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,16 @@ const login = async () => {
143143
}
144144
};
145145

146-
(async () => {
146+
const main = async () => {
147147
const auth = await login();
148148

149149
console.log('User is authenticated', auth);
150150

151151
// Log us out again
152152
await client.logout();
153-
})();
153+
};
154+
155+
main();
154156
```
155157

156158
If you now open the console and visit [localhost:3030](http://localhost:3030) you will see that our user has been authenticated.

0 commit comments

Comments
 (0)