Code Monkey home page Code Monkey logo

Comments (8)

Minivera avatar Minivera commented on May 18, 2024 1

Also wanted to let you know your solution works flawlessly, thanks again!

from encore.

eandre avatar eandre commented on May 18, 2024 1

Thank you @wisdommat, please do! Let me know if you want some help or guidance. Really appreciate the help!

from encore.

eandre avatar eandre commented on May 18, 2024

Hi @Minivera! If you use errs.Error with code errs.Unauthenticated the error message will be propagated:

//encore:authhandler
func AuthHandler(ctx context.Context, token string) (auth.UID, error) {
	return "", errs.B().Code(errs.Unauthenticated).Msg("ask me again tomorrow").Err()
}

Followed by:

# The auth handler's error message is propagated to the user when a token is provided:
$ curl http://localhost:4060/my.Endpoint -H "Authorization: Token foo"
{
  "code": "unauthenticated",
  "message": "ask me again tomorrow",
  "details": null
}

# If no token is given this error is provided directly by Encore and cannot be overridden
$ curl http://localhost:4060/my.Endpoint
{
  "code": "unauthenticated",
  "message": "missing auth token",
  "details": null
}

Maybe I'm misunderstanding what you mean, or does that satisfy your needs?

from encore.

Minivera avatar Minivera commented on May 18, 2024

Oh! Let me try that. I tried by returning a standard error and it triggered a 500, I assumed this part from the docs meant that this was the intended behavior:

If your auth handler returns an error, Encore responds with a 500 Internal Server Error. To signify that the token is not valid, return the empty string ("") as the auth.UID. Encore will then respond with `401 Unauthorized.

My apologies for the misunderstanding.

from encore.

eandre avatar eandre commented on May 18, 2024

That's a great point, the docs should be improved! Will do that, thank you!

from encore.

wisdommatt avatar wisdommatt commented on May 18, 2024

@eandre I will like to work on adding this to the documentation

from encore.

Minivera avatar Minivera commented on May 18, 2024

Apologies for closing the issue randomly, miss-click.

from encore.

wisdommatt avatar wisdommatt commented on May 18, 2024

@eandre i just made a pull request to add this to the docs

from encore.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.