Compare commits
3 Commits
bugfix/iro
...
c884bf812c
| Author | SHA1 | Date | |
|---|---|---|---|
| c884bf812c | |||
| 91f9ed5474 | |||
| adad656df2 |
@@ -25,8 +25,4 @@ time = "0.3"
|
|||||||
oauth2 = { version = "5.0.0", features = ["reqwest"] }
|
oauth2 = { version = "5.0.0", features = ["reqwest"] }
|
||||||
reqwest = { version = "0.13.1", features = ["json"] }
|
reqwest = { version = "0.13.1", features = ["json"] }
|
||||||
rand = "0.9.2"
|
rand = "0.9.2"
|
||||||
uuid = { version = "1", features = ["v4"] }
|
uuid = { version = "1", features = ["v4"] }
|
||||||
sha2 = "0.10"
|
|
||||||
hex = "0.4"
|
|
||||||
tracing = "0.1"
|
|
||||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
|
||||||
@@ -1,10 +1,14 @@
|
|||||||
use axum::{
|
use axum::{
|
||||||
routing::{get, post, put, delete},
|
routing::{get, post, put, delete},
|
||||||
Router, middleware as axum_middleware,
|
Router, middleware as axum_middleware,
|
||||||
|
Extension,
|
||||||
};
|
};
|
||||||
use sea_orm::{sqlx, Database, DatabaseConnection, DbErr};
|
use sea_orm::{sqlx, Database, DatabaseConnection, DbErr};
|
||||||
use sea_orm_migration::prelude::*;
|
use sea_orm_migration::prelude::*;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
use std::time::Instant;
|
||||||
use utoipa::OpenApi;
|
use utoipa::OpenApi;
|
||||||
use utoipa_swagger_ui::SwaggerUi;
|
use utoipa_swagger_ui::SwaggerUi;
|
||||||
use tower_sessions::{Expiry, SessionManagerLayer, cookie::SameSite};
|
use tower_sessions::{Expiry, SessionManagerLayer, cookie::SameSite};
|
||||||
@@ -14,6 +18,12 @@ use time::Duration;
|
|||||||
use tower_http::cors::CorsLayer;
|
use tower_http::cors::CorsLayer;
|
||||||
use axum::http::{Method, HeaderValue};
|
use axum::http::{Method, HeaderValue};
|
||||||
|
|
||||||
|
pub enum MobileStoreEntry {
|
||||||
|
Csrf { created_at: Instant },
|
||||||
|
AuthToken { user_id: i32, created_at: Instant },
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type MobileTokenStore = Arc<Mutex<HashMap<String, MobileStoreEntry>>>;
|
||||||
|
|
||||||
pub mod models;
|
pub mod models;
|
||||||
pub mod services;
|
pub mod services;
|
||||||
@@ -169,10 +179,13 @@ pub async fn create_app(db: DatabaseConnection) -> Result<Router, DbErr> {
|
|||||||
.layer(auth_layer.clone())
|
.layer(auth_layer.clone())
|
||||||
.with_state(db.clone());
|
.with_state(db.clone());
|
||||||
|
|
||||||
|
let mobile_token_store: MobileTokenStore = Arc::new(Mutex::new(HashMap::new()));
|
||||||
|
|
||||||
let oauth_routes = Router::new()
|
let oauth_routes = Router::new()
|
||||||
.route("/auth/google", get(routes::oauth::google_auth))
|
.route("/auth/google", get(routes::oauth::google_auth))
|
||||||
.route("/auth/google/callback", get(routes::oauth::google_callback))
|
.route("/auth/google/callback", get(routes::oauth::google_callback))
|
||||||
.route("/auth/mobile-callback", get(routes::oauth::mobile_callback))
|
.route("/auth/mobile-callback", get(routes::oauth::mobile_callback))
|
||||||
|
.layer(Extension(mobile_token_store))
|
||||||
.layer(auth_layer.clone())
|
.layer(auth_layer.clone())
|
||||||
.with_state(db.clone());
|
.with_state(db.clone());
|
||||||
|
|
||||||
@@ -231,7 +244,7 @@ pub async fn create_app(db: DatabaseConnection) -> Result<Router, DbErr> {
|
|||||||
.url("/api-docs/openapi.json", ApiDoc::openapi());
|
.url("/api-docs/openapi.json", ApiDoc::openapi());
|
||||||
|
|
||||||
let allowed_origins = std::env::var("ALLOWED_ORIGINS")
|
let allowed_origins = std::env::var("ALLOWED_ORIGINS")
|
||||||
.unwrap_or_else(|_| "http://localhost:3000,http://localhost:5173,http://localhost:5174,http://localhost:5175,http://localhost:8080,http://localhost:1420,http://tauri.localhost,https://tauri.localhost".to_string());
|
.unwrap_or_else(|_| "http://localhost:3000,http://localhost:5173,http://localhost:5174,http://localhost:5175,http://localhost:8080".to_string());
|
||||||
|
|
||||||
let origins: Vec<HeaderValue> = allowed_origins
|
let origins: Vec<HeaderValue> = allowed_origins
|
||||||
.split(',')
|
.split(',')
|
||||||
|
|||||||
@@ -3,13 +3,6 @@ use sea_orm::DbErr;
|
|||||||
use sea_orm_migration::prelude::*;
|
use sea_orm_migration::prelude::*;
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), DbErr> {
|
async fn main() -> Result<(), DbErr> {
|
||||||
tracing_subscriber::fmt()
|
|
||||||
.with_env_filter(
|
|
||||||
tracing_subscriber::EnvFilter::try_from_default_env()
|
|
||||||
.unwrap_or_else(|_| "family_budget=debug,info".parse().unwrap()),
|
|
||||||
)
|
|
||||||
.init();
|
|
||||||
|
|
||||||
let db = establish_connection().await?;
|
let db = establish_connection().await?;
|
||||||
println!("Successfully connected to database!");
|
println!("Successfully connected to database!");
|
||||||
|
|
||||||
|
|||||||
@@ -2,82 +2,23 @@ use axum::{
|
|||||||
extract::{Query, State},
|
extract::{Query, State},
|
||||||
http::StatusCode,
|
http::StatusCode,
|
||||||
response::{Html, IntoResponse, Redirect, Response},
|
response::{Html, IntoResponse, Redirect, Response},
|
||||||
|
Extension,
|
||||||
Json,
|
Json,
|
||||||
};
|
};
|
||||||
use axum_login::AuthSession;
|
use axum_login::AuthSession;
|
||||||
use sea_orm::{DatabaseConnection, EntityTrait};
|
use sea_orm::{DatabaseConnection, EntityTrait};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sha2::{Digest, Sha256};
|
|
||||||
use tower_sessions::Session;
|
use tower_sessions::Session;
|
||||||
use tracing::{info, warn};
|
|
||||||
use utoipa::ToSchema;
|
use utoipa::ToSchema;
|
||||||
|
|
||||||
use crate::auth::AuthBackend;
|
use crate::auth::AuthBackend;
|
||||||
use crate::models::User;
|
use crate::models::User;
|
||||||
use crate::services::OAuthService;
|
use crate::services::OAuthService;
|
||||||
|
use crate::{MobileStoreEntry, MobileTokenStore};
|
||||||
|
|
||||||
const CSRF_TOKEN_KEY: &str = "oauth_csrf_token";
|
const CSRF_TOKEN_KEY: &str = "oauth_csrf_token";
|
||||||
const FRONTEND_URL_KEY: &str = "oauth_frontend_url";
|
const FRONTEND_URL_KEY: &str = "oauth_frontend_url";
|
||||||
|
|
||||||
fn mobile_secret() -> String {
|
|
||||||
std::env::var("MOBILE_SECRET").unwrap_or_else(|_| "family-budget-mobile-secret".to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn sign(data: &str) -> String {
|
|
||||||
let secret = mobile_secret();
|
|
||||||
let mut hasher = Sha256::new();
|
|
||||||
hasher.update(format!("{}:{}", secret, data).as_bytes());
|
|
||||||
hex::encode(hasher.finalize())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn make_mobile_csrf_state(nonce: &str) -> String {
|
|
||||||
let sig = sign(&format!("csrf.mobile.{}", nonce));
|
|
||||||
format!("mobile.{}.{}", nonce, sig)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn verify_mobile_csrf_state(state: &str) -> bool {
|
|
||||||
let mut parts = state.splitn(3, '.');
|
|
||||||
match (parts.next(), parts.next(), parts.next()) {
|
|
||||||
(Some("mobile"), Some(nonce), Some(sig)) => {
|
|
||||||
sign(&format!("csrf.mobile.{}", nonce)) == sig
|
|
||||||
}
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn make_auth_token(user_id: i32) -> String {
|
|
||||||
let timestamp = std::time::SystemTime::now()
|
|
||||||
.duration_since(std::time::UNIX_EPOCH)
|
|
||||||
.unwrap()
|
|
||||||
.as_secs();
|
|
||||||
let payload = format!("{}.{}", user_id, timestamp);
|
|
||||||
let sig = sign(&format!("auth.{}", payload));
|
|
||||||
format!("{}.{}", payload, sig)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn verify_auth_token(token: &str) -> Option<i32> {
|
|
||||||
let mut parts = token.splitn(3, '.');
|
|
||||||
let user_id_str = parts.next()?;
|
|
||||||
let timestamp_str = parts.next()?;
|
|
||||||
let sig = parts.next()?;
|
|
||||||
|
|
||||||
let payload = format!("{}.{}", user_id_str, timestamp_str);
|
|
||||||
if sign(&format!("auth.{}", payload)) != sig {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
let timestamp: u64 = timestamp_str.parse().ok()?;
|
|
||||||
let now = std::time::SystemTime::now()
|
|
||||||
.duration_since(std::time::UNIX_EPOCH)
|
|
||||||
.unwrap()
|
|
||||||
.as_secs();
|
|
||||||
if now.saturating_sub(timestamp) > 300 {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
user_id_str.parse().ok()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, ToSchema)]
|
#[derive(Debug, Deserialize, ToSchema)]
|
||||||
pub struct GoogleAuthQuery {
|
pub struct GoogleAuthQuery {
|
||||||
pub redirect_url: Option<String>,
|
pub redirect_url: Option<String>,
|
||||||
@@ -100,8 +41,7 @@ pub struct OAuthUrlResponse {
|
|||||||
path = "/auth/google",
|
path = "/auth/google",
|
||||||
tag = "auth",
|
tag = "auth",
|
||||||
params(
|
params(
|
||||||
("redirect_url" = Option<String>, Query, description = "Frontend URL to redirect after auth"),
|
("redirect_url" = Option<String>, Query, description = "Frontend URL to redirect after auth")
|
||||||
("mobile" = Option<bool>, Query, description = "Mobile OAuth flow")
|
|
||||||
),
|
),
|
||||||
responses(
|
responses(
|
||||||
(status = 200, description = "Returns Google OAuth URL", body = OAuthUrlResponse)
|
(status = 200, description = "Returns Google OAuth URL", body = OAuthUrlResponse)
|
||||||
@@ -109,30 +49,30 @@ pub struct OAuthUrlResponse {
|
|||||||
)]
|
)]
|
||||||
pub async fn google_auth(
|
pub async fn google_auth(
|
||||||
session: Session,
|
session: Session,
|
||||||
|
Extension(token_store): Extension<MobileTokenStore>,
|
||||||
Query(query): Query<GoogleAuthQuery>,
|
Query(query): Query<GoogleAuthQuery>,
|
||||||
) -> Result<Json<OAuthUrlResponse>, StatusCode> {
|
) -> Result<Json<OAuthUrlResponse>, StatusCode> {
|
||||||
let oauth_service = OAuthService::new();
|
let oauth_service = OAuthService::new();
|
||||||
|
|
||||||
if query.mobile.unwrap_or(false) {
|
|
||||||
let nonce = uuid::Uuid::new_v4().to_string();
|
|
||||||
let mobile_state = make_mobile_csrf_state(&nonce);
|
|
||||||
let auth_url = oauth_service.get_auth_url_with_state(mobile_state);
|
|
||||||
info!("mobile google_auth: generated signed state for nonce={}", nonce);
|
|
||||||
return Ok(Json(OAuthUrlResponse { url: auth_url }));
|
|
||||||
}
|
|
||||||
|
|
||||||
let (auth_url, csrf_token) = oauth_service.get_auth_url();
|
let (auth_url, csrf_token) = oauth_service.get_auth_url();
|
||||||
|
|
||||||
session
|
if query.mobile.unwrap_or(false) {
|
||||||
.insert(CSRF_TOKEN_KEY, csrf_token.secret().clone())
|
let mut store = token_store.lock().unwrap();
|
||||||
.await
|
store.insert(
|
||||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
format!("csrf:{}", csrf_token.secret()),
|
||||||
|
MobileStoreEntry::Csrf { created_at: std::time::Instant::now() },
|
||||||
if let Some(redirect_url) = query.redirect_url {
|
);
|
||||||
|
} else {
|
||||||
session
|
session
|
||||||
.insert(FRONTEND_URL_KEY, redirect_url)
|
.insert(CSRF_TOKEN_KEY, csrf_token.secret().clone())
|
||||||
.await
|
.await
|
||||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||||
|
|
||||||
|
if let Some(redirect_url) = query.redirect_url {
|
||||||
|
session
|
||||||
|
.insert(FRONTEND_URL_KEY, redirect_url)
|
||||||
|
.await
|
||||||
|
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Json(OAuthUrlResponse { url: auth_url }))
|
Ok(Json(OAuthUrlResponse { url: auth_url }))
|
||||||
@@ -151,25 +91,34 @@ pub async fn google_callback(
|
|||||||
mut auth_session: AuthSession<AuthBackend>,
|
mut auth_session: AuthSession<AuthBackend>,
|
||||||
session: Session,
|
session: Session,
|
||||||
State(db): State<DatabaseConnection>,
|
State(db): State<DatabaseConnection>,
|
||||||
|
Extension(token_store): Extension<MobileTokenStore>,
|
||||||
Query(query): Query<GoogleCallbackQuery>,
|
Query(query): Query<GoogleCallbackQuery>,
|
||||||
) -> Result<Response, StatusCode> {
|
) -> Result<Response, StatusCode> {
|
||||||
let is_mobile = verify_mobile_csrf_state(&query.state);
|
let session_csrf: Option<String> = session
|
||||||
info!("google_callback: state={} is_mobile={}", &query.state[..query.state.len().min(20)], is_mobile);
|
.get(CSRF_TOKEN_KEY)
|
||||||
|
.await
|
||||||
|
.unwrap_or(None);
|
||||||
|
|
||||||
if !is_mobile {
|
let is_mobile;
|
||||||
let session_csrf: Option<String> = session
|
let csrf_valid;
|
||||||
.get(CSRF_TOKEN_KEY)
|
|
||||||
.await
|
if let Some(csrf) = session_csrf {
|
||||||
.unwrap_or(None);
|
is_mobile = false;
|
||||||
|
csrf_valid = csrf == query.state;
|
||||||
session.remove::<String>(CSRF_TOKEN_KEY).await.ok();
|
session.remove::<String>(CSRF_TOKEN_KEY).await.ok();
|
||||||
|
} else {
|
||||||
|
let key = format!("csrf:{}", &query.state);
|
||||||
|
let mut store = token_store.lock().unwrap();
|
||||||
|
csrf_valid = matches!(
|
||||||
|
store.get(&key),
|
||||||
|
Some(MobileStoreEntry::Csrf { created_at }) if created_at.elapsed().as_secs() < 300
|
||||||
|
);
|
||||||
|
store.remove(&key);
|
||||||
|
is_mobile = csrf_valid;
|
||||||
|
}
|
||||||
|
|
||||||
match session_csrf {
|
if !csrf_valid {
|
||||||
Some(csrf) if csrf == query.state => {}
|
return Err(StatusCode::UNAUTHORIZED);
|
||||||
_ => {
|
|
||||||
warn!("google_callback: CSRF mismatch, session_csrf={:?}", session_csrf.as_deref().map(|s| &s[..s.len().min(10)]));
|
|
||||||
return Err(StatusCode::UNAUTHORIZED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let frontend_url: Option<String> = session
|
let frontend_url: Option<String> = session
|
||||||
@@ -196,8 +145,14 @@ pub async fn google_callback(
|
|||||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||||
|
|
||||||
if is_mobile {
|
if is_mobile {
|
||||||
let token = make_auth_token(user.id);
|
let token = uuid::Uuid::new_v4().to_string();
|
||||||
info!("google_callback: mobile auth for user_id={}, token_prefix={}", user.id, &token[..token.len().min(20)]);
|
{
|
||||||
|
let mut store = token_store.lock().unwrap();
|
||||||
|
store.insert(
|
||||||
|
token.clone(),
|
||||||
|
MobileStoreEntry::AuthToken { user_id: user.id, created_at: std::time::Instant::now() },
|
||||||
|
);
|
||||||
|
}
|
||||||
let deep_link = format!("com.arrelin.family-budget-android://auth?token={}", token);
|
let deep_link = format!("com.arrelin.family-budget-android://auth?token={}", token);
|
||||||
let html = format!(
|
let html = format!(
|
||||||
r#"<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0;url={0}"></head><body><script>window.location="{0}"</script></body></html>"#,
|
r#"<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0;url={0}"></head><body><script>window.location="{0}"</script></body></html>"#,
|
||||||
@@ -234,19 +189,26 @@ pub struct MobileCallbackQuery {
|
|||||||
|
|
||||||
pub async fn mobile_callback(
|
pub async fn mobile_callback(
|
||||||
mut auth_session: AuthSession<AuthBackend>,
|
mut auth_session: AuthSession<AuthBackend>,
|
||||||
session: Session,
|
|
||||||
State(db): State<DatabaseConnection>,
|
State(db): State<DatabaseConnection>,
|
||||||
|
Extension(token_store): Extension<MobileTokenStore>,
|
||||||
Query(query): Query<MobileCallbackQuery>,
|
Query(query): Query<MobileCallbackQuery>,
|
||||||
) -> Result<Json<serde_json::Value>, StatusCode> {
|
) -> Result<Json<serde_json::Value>, StatusCode> {
|
||||||
info!("mobile_callback: received token_prefix={}", &query.token[..query.token.len().min(20)]);
|
let user_id = {
|
||||||
let user_id = match verify_auth_token(&query.token) {
|
let mut store = token_store.lock().unwrap();
|
||||||
Some(id) => id,
|
match store.get(&query.token) {
|
||||||
None => {
|
Some(MobileStoreEntry::AuthToken { user_id, created_at })
|
||||||
warn!("mobile_callback: token verification failed for token={}", &query.token[..query.token.len().min(40)]);
|
if created_at.elapsed().as_secs() < 300 =>
|
||||||
return Err(StatusCode::UNAUTHORIZED);
|
{
|
||||||
|
let uid = *user_id;
|
||||||
|
store.remove(&query.token);
|
||||||
|
uid
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
store.remove(&query.token);
|
||||||
|
return Err(StatusCode::UNAUTHORIZED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
info!("mobile_callback: token valid for user_id={}", user_id);
|
|
||||||
|
|
||||||
let user = User::find_by_id(user_id)
|
let user = User::find_by_id(user_id)
|
||||||
.one(&db)
|
.one(&db)
|
||||||
@@ -259,17 +221,5 @@ pub async fn mobile_callback(
|
|||||||
.await
|
.await
|
||||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||||
|
|
||||||
if let Some(family_id) = user.family_id {
|
|
||||||
let mut authorized_families: Vec<i32> = session
|
|
||||||
.get("authorized_families")
|
|
||||||
.await
|
|
||||||
.unwrap_or(None)
|
|
||||||
.unwrap_or_default();
|
|
||||||
if !authorized_families.contains(&family_id) {
|
|
||||||
authorized_families.push(family_id);
|
|
||||||
session.insert("authorized_families", authorized_families).await.ok();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(Json(serde_json::json!({"success": true})))
|
Ok(Json(serde_json::json!({"success": true})))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,26 +44,6 @@ impl OAuthService {
|
|||||||
(auth_url.to_string(), csrf_token)
|
(auth_url.to_string(), csrf_token)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_auth_url_with_state(&self, state: String) -> String {
|
|
||||||
let client_id = std::env::var("GOOGLE_CLIENT_ID")
|
|
||||||
.expect("GOOGLE_CLIENT_ID must be set");
|
|
||||||
let client_secret = std::env::var("GOOGLE_CLIENT_SECRET")
|
|
||||||
.expect("GOOGLE_CLIENT_SECRET must be set");
|
|
||||||
let redirect_url = std::env::var("GOOGLE_REDIRECT_URL")
|
|
||||||
.unwrap_or_else(|_| "http://localhost:8080/api/auth/google/callback".to_string());
|
|
||||||
|
|
||||||
let client = Self::get_client(client_id, client_secret, redirect_url);
|
|
||||||
|
|
||||||
let (auth_url, _) = client
|
|
||||||
.authorize_url(move || CsrfToken::new(state))
|
|
||||||
.add_scope(Scope::new("openid".to_string()))
|
|
||||||
.add_scope(Scope::new("email".to_string()))
|
|
||||||
.add_scope(Scope::new("profile".to_string()))
|
|
||||||
.url();
|
|
||||||
|
|
||||||
auth_url.to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn exchange_code(&self, code: String) -> Result<String, OAuthError> {
|
pub async fn exchange_code(&self, code: String) -> Result<String, OAuthError> {
|
||||||
let client_id = std::env::var("GOOGLE_CLIENT_ID")
|
let client_id = std::env::var("GOOGLE_CLIENT_ID")
|
||||||
.expect("GOOGLE_CLIENT_ID must be set");
|
.expect("GOOGLE_CLIENT_ID must be set");
|
||||||
|
|||||||
@@ -26,24 +26,16 @@ export default function Login() {
|
|||||||
const url = Array.isArray(urls) ? urls[0] : urls;
|
const url = Array.isArray(urls) ? urls[0] : urls;
|
||||||
if (!url.startsWith(DEEP_LINK_SCHEME)) return;
|
if (!url.startsWith(DEEP_LINK_SCHEME)) return;
|
||||||
|
|
||||||
let token: string | null;
|
const token = new URL(url).searchParams.get('token');
|
||||||
try {
|
if (!token) return;
|
||||||
token = new URL(url).searchParams.get('token');
|
|
||||||
} catch {
|
|
||||||
setError(t('login.authError'));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!token) { setError(t('login.authError')); return; }
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
await authApi.mobileCallback(token);
|
await authApi.mobileCallback(token);
|
||||||
const me = await authApi.me();
|
const me = await authApi.me();
|
||||||
setUser(me.data);
|
setUser(me.data);
|
||||||
} catch (err: any) {
|
} catch {
|
||||||
const status = err?.response?.status;
|
setError(t('login.authError'));
|
||||||
const msg = err?.response?.data ? JSON.stringify(err.response.data) : err?.message;
|
|
||||||
setError(`${status ?? 'network'}: ${msg}`);
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -12,20 +12,6 @@ export default defineConfig({
|
|||||||
? 'https://family-budget.duckdns.org'
|
? 'https://family-budget.duckdns.org'
|
||||||
: 'http://localhost:8080',
|
: 'http://localhost:8080',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
configure: (proxy) => {
|
|
||||||
if (process.env.TAURI_DEV_HOST) {
|
|
||||||
proxy.on('proxyRes', (proxyRes) => {
|
|
||||||
const cookies = proxyRes.headers['set-cookie'];
|
|
||||||
if (cookies) {
|
|
||||||
proxyRes.headers['set-cookie'] = cookies.map(cookie =>
|
|
||||||
cookie
|
|
||||||
.replace(/;\s*Secure/gi, '')
|
|
||||||
.replace(/;\s*Domain=[^;]*/gi, '')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
"build": {
|
"build": {
|
||||||
"beforeDevCommand": "npm run dev --prefix ../frontend",
|
"beforeDevCommand": "npm run dev --prefix ../frontend",
|
||||||
"devUrl": "http://localhost:5173",
|
"devUrl": "http://localhost:5173",
|
||||||
"beforeBuildCommand": "VITE_API_BASE_URL=https://family-budget.duckdns.org/api npm run build --prefix ../frontend",
|
"beforeBuildCommand": "npm run build --prefix ../frontend",
|
||||||
"frontendDist": "../frontend/dist"
|
"frontendDist": "../frontend/dist"
|
||||||
},
|
},
|
||||||
"app": {
|
"app": {
|
||||||
|
|||||||
Reference in New Issue
Block a user