File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -101,6 +101,25 @@ export class UsersDb {
101
101
return user ;
102
102
}
103
103
104
+ /**
105
+ * Retrieves the user with the given login from storage.
106
+ *
107
+ * @returns {Promise<User[]> } The User object associated with the given login
108
+ * @throws Will throw an error if the user is not found
109
+ * @memberof UsersDb
110
+ */
111
+ async getAll ( ) : Promise < User [ ] > {
112
+ const records : User [ ] = [ ] ;
113
+
114
+ for ( const record of await this . storage . entries < User > ( ) ) {
115
+ if ( record [ 0 ] . startsWith ( this . prefix ) ) {
116
+ records . push ( record [ 1 ] ) ;
117
+ }
118
+ }
119
+
120
+ return records ;
121
+ }
122
+
104
123
/**
105
124
* Adds a new user to the storage.
106
125
*
Original file line number Diff line number Diff line change @@ -36,6 +36,25 @@ export const userRouter = router({
36
36
}
37
37
} ) ,
38
38
39
+ /**
40
+ * List users records.
41
+ * Throws an error if the user already exists.
42
+ */
43
+ list : authAdminProcedure . query ( async ( { ctx } ) => {
44
+ try {
45
+ const { users } = ctx ;
46
+ const records = await users . getAll ( ) ;
47
+ logger . trace ( `Listed #${ records . length } users` ) ;
48
+ return records ;
49
+ } catch ( error ) {
50
+ logger . error ( 'user.list' , error ) ;
51
+ throw new TRPCError ( {
52
+ code : 'BAD_REQUEST' ,
53
+ message : ( error as Error ) . message ,
54
+ } ) ;
55
+ }
56
+ } ) ,
57
+
39
58
/**
40
59
* Log in an existing user.
41
60
* If successful, generates a new access token and sends it in the response.
You can’t perform that action at this time.
0 commit comments