- add: session_id to the validate token response
- add: session_id to the jwt generated token
This commit is contained in:
@@ -26,16 +26,14 @@ impl AuthService for MyAuthService {
|
||||
|
||||
info!("Login attempt for username: {}", req.username);
|
||||
|
||||
if let Some(user_id) = verify_user(self.db_client.as_ref().clone(), &req.username, &req.password).await {
|
||||
let token = generate_token(&user_id, vec!["user".to_string()])
|
||||
.map_err(|_| Status::internal("Token generation failed"))?;
|
||||
|
||||
if let Some(user) = verify_user(self.db_client.as_ref().clone(), &req.username, &req.password).await {
|
||||
let user_id = user.user_id.to_string();
|
||||
let session_id = uuid::Uuid::new_v4().to_string();
|
||||
let response = self
|
||||
.session_client.as_ref().clone()
|
||||
.create_session(CreateSessionRequest {
|
||||
session_id: session_id.clone(),
|
||||
user_id: user_id.parse().unwrap(),
|
||||
user_id: user.user_id,
|
||||
username: req.username.to_string(),
|
||||
character_id: 0,
|
||||
ip_address: req.ip_address.to_string(),
|
||||
@@ -48,6 +46,9 @@ impl AuthService for MyAuthService {
|
||||
};
|
||||
let session_id = session.into_inner().session_id;
|
||||
|
||||
let token = generate_token(&user_id, &&session_id.clone(), user.roles)
|
||||
.map_err(|_| Status::internal("Token generation failed"))?;
|
||||
|
||||
info!("Login successful for username: {}", req.username);
|
||||
Ok(Response::new(LoginResponse { token, user_id, session_id }))
|
||||
} else {
|
||||
@@ -77,13 +78,15 @@ impl AuthService for MyAuthService {
|
||||
let req = request.into_inner();
|
||||
|
||||
match validate_token(&req.token) {
|
||||
Ok(user_id) => Ok(Response::new(ValidateTokenResponse {
|
||||
Ok(user_data) => Ok(Response::new(ValidateTokenResponse {
|
||||
valid: true,
|
||||
user_id,
|
||||
user_id: user_data.0,
|
||||
session_id: user_data.1,
|
||||
})),
|
||||
Err(_) => Ok(Response::new(ValidateTokenResponse {
|
||||
valid: false,
|
||||
user_id: "".to_string(),
|
||||
session_id: "".to_string(),
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user