Ngx-admin: How to change login error message?

Created on 30 Aug 2018  路  8Comments  路  Source: akveo/ngx-admin

when login with wrong password, it always got this error message: Oh snap!
Something went wrong.
Is this message supposed to be? How can i customize the error message? Thanks!

Most helpful comment

After a deep search in @nebular/auth files I figure out how to do it, you have to override the getter method of the errors of the used strategy, here is an example (where res is the HTTP response of the login request):

NbPasswordAuthStrategy.setup({
  name: 'username',
  token: {
    class: NbAuthJWTToken,
    key: 'token',
  },
  baseEndpoint: '/api',
  login: {
    endpoint: '/auth/login',
    method: 'post',
  },
  logout: {
    endpoint: '/auth/logout',
    method: 'get',
  },
  errors: {
    getter: (module, res, options) => {
      return res.error ? res.error.message : options[module].defaultErrors;
    },
  },
})

All 8 comments

Hi @joeyjin , did your issue resolved?

If not, please, reopen issue in the nebular repo.

After a deep search in @nebular/auth files I figure out how to do it, you have to override the getter method of the errors of the used strategy, here is an example (where res is the HTTP response of the login request):

NbPasswordAuthStrategy.setup({
  name: 'username',
  token: {
    class: NbAuthJWTToken,
    key: 'token',
  },
  baseEndpoint: '/api',
  login: {
    endpoint: '/auth/login',
    method: 'post',
  },
  logout: {
    endpoint: '/auth/logout',
    method: 'get',
  },
  errors: {
    getter: (module, res, options) => {
      return res.error ? res.error.message : options[module].defaultErrors;
    },
  },
})

@bacali95 Do you have any examples of how you did this, I'm facing the same issue.

@bacali95 Do you have any examples of how you did this, I'm facing the same issue.

Here is an example:

NbPasswordAuthStrategy.setup({
  name: 'username',
  token: {
    class: NbAuthJWTToken,
    key: 'token',
  },
  baseEndpoint: '/api',
  login: {
    endpoint: '/auth/login',
    method: 'post',
  },
  logout: {
    endpoint: '/auth/logout',
    method: 'get',
  },
  errors: {
    // Override the getter of errors functions
    // res: is the HttpResponse that you get from your backend 
    getter: (module, res, options) => {
      return res.error ? res.error.message : options[module].defaultErrors;
    },
  },
})

Oh! Nice, it works!

After a deep search in @nebular/auth files I figure out how to do it, you have to override the getter method of the errors of the used strategy, here is an example (where res is the HTTP response of the login request):

NbPasswordAuthStrategy.setup({
  name: 'username',
  token: {
    class: NbAuthJWTToken,
    key: 'token',
  },
  baseEndpoint: '/api',
  login: {
    endpoint: '/auth/login',
    method: 'post',
  },
  logout: {
    endpoint: '/auth/logout',
    method: 'get',
  },
  errors: {
    getter: (module, res, options) => {
      return res.error ? res.error.message : options[module].defaultErrors;
    },
  },
})

This is the best answer!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

maxlein picture maxlein  路  3Comments

AZm1n picture AZm1n  路  4Comments

pulfabio picture pulfabio  路  4Comments

tal-shahar picture tal-shahar  路  3Comments

myurAgarwal picture myurAgarwal  路  3Comments