Closed Exegetech closed 5 years ago
you should be more specific. example shows basics, everything else is api specific
@fafhrd91
I am thinking of how to create a middleware:
Auth guard for specific routes.
For example, routes /todos/*
will need authentication. The middleware will check for token in the cookie, check if the user exists in the database, append that user data to be used in the next request (for example, to create owner_id
for the todo
. If the user is not authenticated or the user does not exist in the database, do a redirect to /login
.
Flash middleware
After the user created a todo, then the user gets redirected to /todos
. I want to display a flash message saying A todo successfully created
using session. This flash message is one time use only. Currently I have to manually clear the flash inside every route. Is there a way to automate this manually clearing the flash. I am thinking if there is a way to check the end of request cycle to clear this flash message, or if there is a way to temporarily save that flash message at the beginning of the request in some app state and clear the flash there.
Hello,
can we put more examples on middleware section for actix-web 1.0.0? I am currently trying to implement a flash middleware that automatically set and erase flash messages, and an auth check middleware that guard specific routes.
Looking at the middleware examples, I still don't understand how to properly do this. Any help is appreciated. If I can implement it correctly I will send a PR for those flash and auth middleware examples.