Compiles, assuming the user id will be in grpc metadata from auth interceptor.
This commit is contained in:
parent
a867fdd831
commit
b4981dfc78
16
src/grpc.rs
16
src/grpc.rs
|
@ -15,7 +15,7 @@ use tonic::{Request, Response, Status};
|
||||||
/// in user does not have the permission to access this character.
|
/// in user does not have the permission to access this character.
|
||||||
async fn load_character(
|
async fn load_character(
|
||||||
conn: &sqlx::SqlitePool,
|
conn: &sqlx::SqlitePool,
|
||||||
logged_in_user: Option<&User>,
|
logged_in_user: Option<User>,
|
||||||
owner: &str,
|
owner: &str,
|
||||||
character_id: i32,
|
character_id: i32,
|
||||||
) -> Result<Character, Error> {
|
) -> Result<Character, Error> {
|
||||||
|
@ -73,6 +73,18 @@ impl CofdApi for CofdApiService {
|
||||||
&self,
|
&self,
|
||||||
request: Request<UpdateSkillValueRequest>, // Accept request of type HelloRequest
|
request: Request<UpdateSkillValueRequest>, // Accept request of type HelloRequest
|
||||||
) -> Result<Response<Skill>, Status> {
|
) -> Result<Response<Skill>, Status> {
|
||||||
|
let user_id: &str = request
|
||||||
|
.metadata()
|
||||||
|
.get("user_id")
|
||||||
|
.and_then(|user_id| user_id.to_str().ok())
|
||||||
|
.ok_or(Error::NotLoggedIn)?;
|
||||||
|
|
||||||
|
let logged_in_user = self
|
||||||
|
.db
|
||||||
|
.load_user(user_id)
|
||||||
|
.await
|
||||||
|
.map_err(|e| Error::from(e))?;
|
||||||
|
|
||||||
//Can use metadata map to add user id inside interceptor for auth.
|
//Can use metadata map to add user id inside interceptor for auth.
|
||||||
let request = request.into_inner();
|
let request = request.into_inner();
|
||||||
let mut character = load_character(
|
let mut character = load_character(
|
||||||
|
@ -96,7 +108,7 @@ impl CofdApi for CofdApiService {
|
||||||
self.db
|
self.db
|
||||||
.update_character_sheet(&character)
|
.update_character_sheet(&character)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| e.into())?; //TODO maybe use crate Error for db
|
.map_err(|e| Error::from(e))?; //TODO maybe use crate Error for db
|
||||||
|
|
||||||
let reply = Skill::default();
|
let reply = Skill::default();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue