Skip to content

Commit 990edc9

Browse files
authored
Merge pull request #14 from which-ecosystem/feed
Feed endpoint
2 parents 0899413 + 0a6a6be commit 990edc9

14 files changed

+178
-89
lines changed

hooks/isAuthenticated.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { HookContext } from '@feathersjs/feathers';
2+
3+
export default async (context: HookContext): Promise<boolean> => {
4+
console.log(context.params.authenticated);
5+
return context.params.authenticated || false;
6+
};
7+

hooks/requireAuth.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import { iff, isNot } from 'feathers-hooks-common';
12
import { NotAuthenticated } from '@feathersjs/errors';
2-
import { HookContext } from '@feathersjs/feathers';
3+
import isAuthenticated from './isAuthenticated';
34

4-
export default async (context: HookContext): Promise<HookContext> => {
5-
if (!context.params.authenticated) {
5+
export default iff(
6+
isNot(isAuthenticated),
7+
() => {
68
throw new NotAuthenticated('This endpoint requires auth!');
79
}
8-
return context;
9-
};
10+
);
1011

hooks/sortByDate.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import _ from 'lodash';
2+
import { HookContext } from '@feathersjs/feathers';
3+
4+
export default async (context: HookContext): Promise<HookContext> => {
5+
_.set(context, 'params.query.$sort', { createdAt: -1 });
6+
return context;
7+
};
8+

models/users/user.schema.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,20 @@ export interface UserSchema extends Document, Omit<User, '_id'> {
66
}
77

88
export const userSchema = new Schema({
9-
username: String,
10-
password: String,
9+
username: {
10+
type: String,
11+
unique: true,
12+
required: true
13+
},
14+
password: {
15+
type: String,
16+
required: true
17+
},
1118
email: String,
19+
verified: {
20+
type: Boolean,
21+
default: false
22+
},
1223
avatarUrl: {
1324
type: String,
1425
required: false

0 commit comments

Comments
 (0)