Firebase error messages in different languages?

前端 未结 3 1854
北恋
北恋 2021-02-05 08:49

Showing the Firebase error messages (error.message) in the view results in english error descriptions (e.g. for Authentication errors, if user credetials contain errors).

<
3条回答
  •  既然无缘
    2021-02-05 09:16

    Here's what I did when I had to make the errors shorter:

    const firebaseErrors = {
      'auth/user-not-found': 'No user corresponding to this email',
      'auth/email-already-in-use': 'The email address is already in use',
    }; // list of firebase error codes to alternate error messages
    

    Then somewhere where you need 'em

    catch (error) {
          throw firebaseErrors[error.code] || error.message,
    }
    

提交回复
热议问题