chore: add logs

This commit is contained in:
nathan 2023-10-13 10:37:28 +08:00
parent 03a2de11e4
commit 7b77805d8d
5 changed files with 22 additions and 4 deletions

View File

@ -29,6 +29,9 @@ jobs:
- name: Replace values in .env
run: |
# log level
sed -i 's|RUST_LOG=.*|RUST_LOG=trace|' .env
sed -i 's/GOTRUE_SMTP_USER=.*/GOTRUE_SMTP_USER=${{ secrets.GOTRUE_SMTP_USER }}/' .env
sed -i 's/GOTRUE_SMTP_PASS=.*/GOTRUE_SMTP_PASS=${{ secrets.GOTRUE_SMTP_PASS }}/' .env
sed -i 's/GOTRUE_SMTP_ADMIN_EMAIL=.*/GOTRUE_SMTP_ADMIN_EMAIL=${{ secrets.GOTRUE_SMTP_ADMIN_EMAIL }}/' .env

View File

@ -418,7 +418,7 @@ impl Client {
Ok(())
}
#[instrument(level = "debug", skip_all, err)]
#[instrument(skip_all, err)]
pub async fn sign_in_password(&self, email: &str, password: &str) -> Result<bool, AppError> {
let access_token_resp = self
.gotrue_client

View File

@ -1,4 +1,6 @@
use anyhow::{Context, Error};
use sqlx::PgPool;
use tracing::instrument;
pub async fn update_user_name(
pool: &PgPool,
@ -19,12 +21,13 @@ pub async fn update_user_name(
Ok(())
}
#[instrument(skip_all, err)]
pub async fn create_user_if_not_exists(
pool: &PgPool,
user_uuid: &uuid::Uuid,
email: &str,
name: &str,
) -> Result<bool, sqlx::Error> {
) -> Result<bool, Error> {
let affected_rows = sqlx::query!(
r#"
INSERT INTO af_user (uuid, email, name)
@ -41,7 +44,11 @@ pub async fn create_user_if_not_exists(
name
)
.execute(pool)
.await?
.await
.context(format!(
"Fail to insert user. uuid: {}, name: {}, email: {}",
user_uuid, name, email
))?
.rows_affected();
Ok(affected_rows > 0)

View File

@ -18,6 +18,7 @@ use actix_web::web::{Data, Json};
use actix_web::HttpRequest;
use actix_web::Result;
use actix_web::{web, HttpResponse, Scope};
use tracing_actix_web::RequestId;
pub fn user_scope() -> Scope {
web::scope("/api/user")
@ -33,9 +34,11 @@ pub fn user_scope() -> Scope {
.service(web::resource("/password").route(web::post().to(change_password_handler)))
}
#[tracing::instrument(skip(state, path), err)]
async fn verify_handler(
path: web::Path<String>,
state: Data<AppState>,
required_id: RequestId,
) -> Result<JsonAppResponse<SignInTokenResponse>> {
let access_token = path.into_inner();
let is_new = biz::user::token_verify(&state.pg_pool, &state.gotrue_client, &access_token).await?;
@ -43,19 +46,22 @@ async fn verify_handler(
Ok(AppResponse::Ok().with_data(resp).into())
}
#[tracing::instrument(level = "debug", skip(state))]
#[tracing::instrument(skip(state), err)]
async fn profile_handler(
uuid: UserUuid,
state: Data<AppState>,
required_id: RequestId,
) -> Result<JsonAppResponse<AFUserProfileView>> {
let profile = biz::user::get_profile(&state.pg_pool, &uuid).await?;
Ok(AppResponse::Ok().with_data(profile).into())
}
#[tracing::instrument(skip(state, auth, req), err)]
async fn update_handler(
auth: Authorization,
req: Json<UpdateUsernameParams>,
state: Data<AppState>,
required_id: RequestId,
) -> Result<JsonAppResponse<()>> {
let params = req.into_inner();
biz::user::update_user(&state.pg_pool, &auth.uuid()?, &params.new_name).await?;

View File

@ -18,6 +18,7 @@ use sqlx::{PgPool, Postgres, Transaction};
use std::sync::Arc;
use token::{create_token, parse_token, TokenError};
use tokio::sync::RwLock;
use tracing::instrument;
pub async fn login(
email: String,
@ -51,6 +52,7 @@ pub async fn logout(logged_user: LoggedUser, cache: Arc<RwLock<UserCache>>) {
cache.write().await.unauthorized(logged_user);
}
#[instrument(skip_all, err)]
pub async fn register(
username: String,
email: String,