Skip to content

How to use api token in some enpoints #319

Answered by kaplanelad
enieber asked this question in Q&A
Discussion options

You must be logged in to vote

Hey, @enieber, yes, this is something that Loco provides already.

go you your controller and add auth: auth::ApiToken<users::Model> middleware into your controller.
for example:

async fn products(
    auth: auth::ApiToken<users::Model>,
    State(_ctx): State<AppContext>,
) -> Result<Json<CurrentResponse>> {
   ...
}

The ApiToken will check the user token.

It looks like we didn't document it at all. Nice catch!
I have opened an issue for that #325

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by enieber
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants