File tree Expand file tree Collapse file tree 10 files changed +225
-3
lines changed Expand file tree Collapse file tree 10 files changed +225
-3
lines changed Original file line number Diff line number Diff line change 1
1
import feathers from '@feathersjs/feathers' ;
2
2
import express from '@feathersjs/express' ;
3
3
import socketio from '@feathersjs/socketio' ;
4
+ import configuration from '@feathersjs/configuration'
4
5
import '@feathersjs/transport-commons' ;
5
6
import cors from 'cors' ;
6
7
@@ -15,6 +16,7 @@ app.use(express.static(__dirname));
15
16
app . use ( express . errorHandler ( ) ) ;
16
17
app . use ( cors ( ) ) ;
17
18
19
+ app . configure ( configuration ( ) ) ;
18
20
app . configure ( express . rest ( ) ) ;
19
21
app . configure ( socketio ( ) ) ;
20
22
app . configure ( services ) ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "authentication" : {
3
+ "secret" : " 2JtbBy2ycQ1V3kQfPcSgXYmFsB7" ,
4
+ "service" : " users" ,
5
+ "authStrategies" : [
6
+ " jwt" ,
7
+ " local"
8
+ ],
9
+ "local" : {
10
+ "usernameField" : " name" ,
11
+ "passwordField" : " password"
12
+ }
13
+ }
14
+ }
Original file line number Diff line number Diff line change @@ -6,10 +6,13 @@ export interface User {
6
6
age ?: number ;
7
7
}
8
8
9
- export interface UserSchema extends Document , User { }
9
+ export interface UserSchema extends Document , User {
10
+ password : string ;
11
+ }
10
12
11
13
export const userSchema = new Schema ( {
12
14
name : String ,
15
+ password : String ,
13
16
avatarUrl : {
14
17
type : String ,
15
18
required : false
Original file line number Diff line number Diff line change 10
10
"author" : " " ,
11
11
"license" : " ISC" ,
12
12
"dependencies" : {
13
+ "@feathersjs/authentication" : " ^4.5.3" ,
14
+ "@feathersjs/authentication-local" : " ^4.5.4" ,
15
+ "@feathersjs/configuration" : " ^4.5.3" ,
13
16
"@feathersjs/express" : " ^4.5.4" ,
14
17
"@feathersjs/feathers" : " ^4.5.3" ,
15
18
"@feathersjs/socketio" : " ^4.5.4" ,
Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ const createPoll = (authorId: string): Promise<PollSchema> => {
46
46
const createUser = ( name : string ) : Promise < UserSchema > => {
47
47
return app . service ( 'users' ) . create ( {
48
48
avatarUrl : _ . sample ( imageUrls ) || '' ,
49
+ password : 'supersecret' ,
49
50
name
50
51
} ) ;
51
52
} ;
Original file line number Diff line number Diff line change
1
+ import {
2
+ AuthenticationService ,
3
+ JWTStrategy
4
+ } from '@feathersjs/authentication' ;
5
+ import { LocalStrategy } from '@feathersjs/authentication-local' ;
6
+ import { Application } from '@feathersjs/express' ;
7
+
8
+ export default ( app : Application ) : void => {
9
+ const authentication = new AuthenticationService ( app ) ;
10
+
11
+ authentication . register ( 'local' , new LocalStrategy ( ) ) ;
12
+ authentication . register ( 'jwt' , new JWTStrategy ( ) ) ;
13
+
14
+ app . use ( '/authentication' , authentication ) ;
15
+ } ;
16
+
Original file line number Diff line number Diff line change @@ -2,8 +2,10 @@ import { Application } from '@feathersjs/express';
2
2
import Users from './users/users.service' ;
3
3
import Polls from './polls/polls.service' ;
4
4
import Profiles from './profiles/profiles.service' ;
5
+ import Auth from './auth/auth.service' ;
5
6
6
7
export default ( app : Application ) : void => {
8
+ app . configure ( Auth ) ;
7
9
app . configure ( Users ) ;
8
10
app . configure ( Polls ) ;
9
11
app . configure ( Profiles ) ;
Original file line number Diff line number Diff line change
1
+ import { hooks } from '@feathersjs/authentication-local' ;
2
+
3
+ const hashPassword = hooks . hashPassword ( 'password' ) ;
4
+ const protectPassword = hooks . protect ( 'password' ) ;
5
+
6
+ export default {
7
+ after : {
8
+ all : [ protectPassword ]
9
+ } ,
10
+ before : {
11
+ create : [ hashPassword ] ,
12
+ patch : [ hashPassword ] ,
13
+ update : [ hashPassword ]
14
+ }
15
+ } ;
16
+
Original file line number Diff line number Diff line change 1
1
import { Application } from '@feathersjs/express' ;
2
2
import service from 'feathers-mongoose' ;
3
3
import Model from '../../models/users/user.model' ;
4
+ import hooks from './users.hooks' ;
4
5
5
6
const UserService = service ( { Model } ) ;
6
7
7
8
export default ( app : Application ) : void => {
8
9
app . use ( '/users' , UserService ) ;
10
+ app . service ( 'users' ) . hooks ( hooks ) ;
9
11
} ;
10
12
You can’t perform that action at this time.
0 commit comments