@@ -113,8 +113,7 @@ function checkIfUserIsModerator() {
113113
114114export async function connectParseServer (
115115 jwtToken : string ,
116- userId : string
117- //,returnParseUser: (user: any) => void
116+ emailAddress : string
118117) {
119118 return new Promise < any > ( ( resolve , reject ) => {
120119 const connection = getConnection ( ) ;
@@ -130,7 +129,7 @@ export async function connectParseServer(
130129 `${ connection . url } functions/bloomLink` ,
131130 {
132131 token : jwtToken ,
133- id : userId ,
132+ id : emailAddress ,
134133 } ,
135134
136135 {
@@ -144,32 +143,49 @@ export async function connectParseServer(
144143 `${ connection . url } users` ,
145144 {
146145 authData : {
147- bloom : { token : jwtToken , id : userId } ,
146+ bloom : { token : jwtToken , id : emailAddress } ,
148147 } ,
149- username : userId ,
150- email : userId , // needed in case we are creating a new user
148+ username : emailAddress ,
149+ // Parse requires an `email` field when creating a new _User.
150+ email : emailAddress ,
151151 } ,
152152
153153 {
154154 headers : connection . headers ,
155155 }
156156 )
157157 . then ( ( usersResult ) => {
158- if ( usersResult . data . sessionToken ) {
158+ // We require BOTH a session token and an email.
159+ // We don't actually know why we would ever get here without either.
160+ // But we were sending posts to Bloom with a missing email value in the payload,
161+ // which caused Bloom's `/bloom/api/external/login` handler to throw a runtime exception. See BL-14503.
162+ // I don't see any reason to pretend a non-editor login was successful if email
163+ // is missing, either. And it simplifies the code to just check up front.
164+ if (
165+ usersResult . data . sessionToken &&
166+ usersResult . data . email
167+ ) {
159168 LoggedInUser . current = new User ( usersResult . data ) ;
160- //Object.assign(CurrentUser, usersResult.data);
161169 connection . headers [ "X-Parse-Session-Token" ] =
162170 usersResult . data . sessionToken ;
163171
164172 if ( isForEditor ( ) ) {
165173 informEditorOfSuccessfulLogin ( usersResult . data ) ;
166174 }
167175
168- //console.log("Got ParseServer Session ID");
169176 resolve ( usersResult . data ) ;
170- //returnParseUser(result.data);
171177 checkIfUserIsModerator ( ) ;
172- } else failedToLoginInToParseServer ( ) ;
178+ } else {
179+ failedToLoginInToParseServer ( ) ;
180+ // Reject the Promise returned by `connectParseServer()`.
181+ // This lets callers stop the login flow (for example, `firebase.ts` catches this and
182+ // signs the user out of Firebase) rather than silently continuing.
183+ reject (
184+ new Error (
185+ "Missing sessionToken or email in usersResult.data"
186+ )
187+ ) ;
188+ }
173189 } )
174190 . catch ( ( err ) => {
175191 failedToLoginInToParseServer ( ) ;
0 commit comments