add cookies
This commit is contained in:
parent
627aea08cb
commit
c5f6a24b3a
6 changed files with 59 additions and 8 deletions
|
|
@ -12,6 +12,7 @@ use axum::{middleware, Json, Router};
|
|||
use axum::Server;
|
||||
use serde::Deserialize;
|
||||
use tower_http::services::ServeDir;
|
||||
use tower_cookies::CookieManagerLayer;
|
||||
|
||||
|
||||
mod error;
|
||||
|
|
@ -28,6 +29,7 @@ async fn main() {
|
|||
.merge(routes_hello())
|
||||
.merge(web::routes_login::routes())
|
||||
.layer(middleware::map_response(main_response_mapper))
|
||||
.layer(CookieManagerLayer::new())
|
||||
.fallback_service(routes_static());
|
||||
|
||||
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
|
||||
|
|
|
|||
|
|
@ -1 +1,3 @@
|
|||
pub mod routes_login;
|
||||
|
||||
pub const AUTH_TOKEN: &str = "auth-token";
|
||||
|
|
|
|||
|
|
@ -1,21 +1,23 @@
|
|||
use crate::{Error, Result};
|
||||
use crate::{Error, Result, web};
|
||||
use axum::{Json, Router};
|
||||
use axum::routing::post;
|
||||
use serde::Deserialize;
|
||||
use serde_json::{json, Value};
|
||||
use tower_cookies::{Cookie, Cookies};
|
||||
|
||||
pub fn routes() -> Router {
|
||||
Router::new().route("/api/login", post(api_login))
|
||||
}
|
||||
|
||||
async fn api_login(payload: Json<LoginPayload>) -> Result<Json<Value>>{
|
||||
async fn api_login(cookies: Cookies, payload: Json<LoginPayload>) -> Result<Json<Value>>{
|
||||
println!("->> {:<12} - api_login", "HANDLER");
|
||||
|
||||
if payload.username != "demo1" || payload.password != "demo1" {
|
||||
return Err(Error::LoginFail);
|
||||
}
|
||||
|
||||
// TODO: Set cookies
|
||||
// FIXME: Implement real auth-token generation/signature.
|
||||
cookies.add(Cookie::new(web::AUTH_TOKEN, "user-1.exp.sign"));
|
||||
|
||||
let body = Json(json!({
|
||||
"result": {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue