Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate error messages #153

Open
jpaiardi opened this issue Feb 15, 2019 · 2 comments
Open

Translate error messages #153

jpaiardi opened this issue Feb 15, 2019 · 2 comments
Labels

Comments

@jpaiardi
Copy link

Hi,
Is it possible to modify (translate) the error messages that are generated, for example when not receiving a token?

@tuupola
Copy link
Owner

tuupola commented Feb 17, 2019

Not directly, but you could use the error handler. Let's assume you have created a translating function translate_error($locale, $message) then the error handler would be something like:

$app = new Slim\App;

$app->add(new Tuupola\Middleware\JwtAuthentication([
    "secret" => "supersecretkeyyoushouldnotcommittogithub",
    "error" => function ($response, $arguments) {
        $data["status"] = "error";
        $data["message"] = translate_error("et_EE", $arguments["message"]);
        return $response
            ->withHeader("Content-Type", "application/json")
            ->getBody()->write(json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
    }
]));

@thepercival
Copy link

thepercival commented Mar 30, 2020

Problem with translating the message, is that when the message in english changes, there will be no translation and the developer will not know.
When a token expires Firebase\JW\ExpiredException is thrown. From a user(other developer)-view would it not be better to be able to catch the Firebase\JW\ExpiredException instead of handling the "error"-function( "error" => function ($response, $arguments) { ... } )?

I have been using your library for a few years now and I want to thank you for the effort and functionality btw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants