|
1 | 1 | use crate::{config::db::Pool, constants, models::response::ResponseBody, utils::token_utils}; |
2 | 2 | use actix_service::{Service, Transform}; |
3 | 3 | use actix_web::{ |
| 4 | + http::{Method}, |
4 | 5 | dev::{ServiceRequest, ServiceResponse}, |
5 | 6 | Error, HttpResponse, |
6 | 7 | }; |
@@ -64,36 +65,38 @@ where |
64 | 65 | // debug!("{:?}",pl); |
65 | 66 | // let req2 = ServiceRequest::from_parts(r, pl); |
66 | 67 | // assert!(ServiceRequest::from_parts(r, pl).is_ok()); |
67 | | - for ignore_route in constants::IGNORE_ROUTES.iter() { |
68 | | - debug!("route:{}",ignore_route); |
69 | | - if req.path().starts_with(ignore_route) { |
70 | | - authenticate_pass = true; |
| 68 | + if Method::OPTIONS == *req.method() { |
| 69 | + authenticate_pass = true; |
| 70 | + } else { |
| 71 | + for ignore_route in constants::IGNORE_ROUTES.iter() { |
| 72 | + debug!("route:{}",ignore_route); |
| 73 | + if req.path().starts_with(ignore_route) { |
| 74 | + authenticate_pass = true; |
| 75 | + } |
71 | 76 | } |
72 | | - } |
73 | 77 |
|
74 | | - if let Some(pool) = req.app_data::<Pool>() { |
75 | | - info!("Connecting to database..."); |
76 | | - if let Some(authen_header) = req.headers_mut().get(constants::AUTHORIZATION) { |
77 | | - info!("Parsing authorization header..."); |
78 | | - if let Ok(authen_str) = authen_header.to_str() { |
79 | | - if authen_str.starts_with("bearer") || authen_str.starts_with("Bearer") { |
80 | | - info!("Parsing token..."); |
81 | | - let token = authen_str[6..authen_str.len()].trim(); |
82 | | - if let Ok(token_data) = token_utils::decode_token(token.to_string()) { |
83 | | - info!("Decoding token..."); |
84 | | - if token_utils::verify_token(&token_data, &pool).is_ok() { |
85 | | - info!("Valid token"); |
86 | | - authenticate_pass = true; |
87 | | - } else { |
88 | | - error!("Invalid token"); |
| 78 | + if let Some(pool) = req.app_data::<Pool>() { |
| 79 | + info!("Connecting to database..."); |
| 80 | + if let Some(authen_header) = req.headers_mut().get(constants::AUTHORIZATION) { |
| 81 | + info!("Parsing authorization header..."); |
| 82 | + if let Ok(authen_str) = authen_header.to_str() { |
| 83 | + if authen_str.starts_with("bearer") || authen_str.starts_with("Bearer") { |
| 84 | + info!("Parsing token..."); |
| 85 | + let token = authen_str[6..authen_str.len()].trim(); |
| 86 | + if let Ok(token_data) = token_utils::decode_token(token.to_string()) { |
| 87 | + info!("Decoding token..."); |
| 88 | + if token_utils::verify_token(&token_data, &pool).is_ok() { |
| 89 | + info!("Valid token"); |
| 90 | + authenticate_pass = true; |
| 91 | + } else { |
| 92 | + error!("Invalid token"); |
| 93 | + } |
89 | 94 | } |
90 | 95 | } |
91 | 96 | } |
92 | 97 | } |
93 | 98 | } |
94 | 99 | } |
95 | | - |
96 | | - error!("{}", constants::MESSAGE_PROCESS_TOKEN_ERROR); |
97 | 100 | if authenticate_pass { |
98 | 101 | let fut = self.service.call(req); |
99 | 102 | Box::pin(async move { |
|
0 commit comments