File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,14 @@ class Context {
122
122
. select ( 'comments.id' , db . raw ( 'count(comment_points.comment_id)' ) )
123
123
. then ( mapToValues ( keys , x => x . id , x => x . count ) ) ,
124
124
) ;
125
+
126
+ /*
127
+ * Authenticatinon and permissions.
128
+ */
129
+
130
+ ensureIsAuthenticated ( ) {
131
+ if ( ! this . user ) throw new Error ( 'Anonymous access is denied.' ) ;
132
+ }
125
133
}
126
134
127
135
export default Context ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Node.js API Starter Kit (https://reactstarter.com/nodejs)
3
+ *
4
+ * Copyright © 2016-present Kriasoft, LLC. All rights reserved.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE.txt file in the root directory of this source tree.
8
+ */
9
+
10
+ /* eslint-env jest */
11
+
12
+ import Context from '../Context' ;
13
+
14
+ describe ( 'Context' , ( ) => {
15
+ test ( 'ensureIsAuthenticated()' , ( ) => {
16
+ const ctx1 = new Context ( { user : null } ) ;
17
+ const ctx2 = new Context ( { user : { } } ) ;
18
+ expect ( ( ) => ctx1 . ensureIsAuthenticated ( ) ) . toThrow ( ) ;
19
+ expect ( ( ) => ctx2 . ensureIsAuthenticated ( ) ) . not . toThrow ( ) ;
20
+ } ) ;
21
+ } ) ;
You can’t perform that action at this time.
0 commit comments