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!
You may take a look at https://akveo.github.io/nebular/docs/auth/configuring-ui#custom-ui-components
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
gettermethod of the errors of the used strategy, here is an example (whereresis 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!
Most helpful comment
After a deep search in @nebular/auth files I figure out how to do it, you have to override the
gettermethod of the errors of the used strategy, here is an example (whereresis the HTTP response of the login request):