File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -273,6 +273,27 @@ class UserStore {
273273 } )
274274 }
275275
276+ /**
277+ * Loads and returns a user object for a given email.
278+ *
279+ * @param email {string}
280+ *
281+ * @return {Promise<Object> } User info, parsed from a JSON string
282+ */
283+ findUserByEmail ( email ) {
284+ const emailKey = UserStore . normalizeEmailKey ( email )
285+
286+ return this . backend . get ( 'users-by-email' , emailKey )
287+ . then ( user => {
288+ if ( user && user . link ) {
289+ // this is an alias record, fetch the user it points to
290+ return this . findUser ( user . link )
291+ }
292+
293+ return user
294+ } )
295+ }
296+
276297 /**
277298 * Creates and returns a salted password hash, for storage with the user
278299 * record.
Original file line number Diff line number Diff line change @@ -192,6 +192,21 @@ describe('UserStore', () => {
192192 } )
193193 } )
194194
195+ it ( 'should look up user record by normalized email' , ( ) => {
196+ const email = 'alice@example.com'
197+ const user = { id : 'abc' , email : email }
198+
199+ store . backend . get = sinon . stub ( ) . resolves ( user )
200+
201+ return store . findUserByEmail ( email )
202+ . then ( fetchedUser => {
203+ expect ( fetchedUser ) . to . equal ( user )
204+
205+ expect ( store . backend . get ) . to . have . been
206+ . calledWith ( 'users-by-email' , 'alice%40example.com' )
207+ } )
208+ } )
209+
195210 it ( 'should look up user record via an alias record' , ( ) => {
196211 const aliasId = 'alice.solidtest.space/profile/card#me'
197212 const aliasKey = 'alice.solidtest.space%2Fprofile%2Fcard%23me'
You can’t perform that action at this time.
0 commit comments