diff --git a/.sqlx/query-7117da081c490f3dac2238338122e15c5be41855aac90a848998324f0c8819af.json b/.sqlx/query-7117da081c490f3dac2238338122e15c5be41855aac90a848998324f0c8819af.json new file mode 100644 index 0000000..a741182 --- /dev/null +++ b/.sqlx/query-7117da081c490f3dac2238338122e15c5be41855aac90a848998324f0c8819af.json @@ -0,0 +1,14 @@ +{ + "db_name": "PostgreSQL", + "query": "\n INSERT INTO profiles(username)\n VALUES ($1) \n ON CONFLICT (user_id) DO UPDATE\n SET username = $1\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Varchar" + ] + }, + "nullable": [] + }, + "hash": "7117da081c490f3dac2238338122e15c5be41855aac90a848998324f0c8819af" +} diff --git a/.sqlx/query-989226d5c28e957f3bb8a763f9e7b3d435a130ac9c81b8bd902d184684a12a5c.json b/.sqlx/query-989226d5c28e957f3bb8a763f9e7b3d435a130ac9c81b8bd902d184684a12a5c.json new file mode 100644 index 0000000..4499774 --- /dev/null +++ b/.sqlx/query-989226d5c28e957f3bb8a763f9e7b3d435a130ac9c81b8bd902d184684a12a5c.json @@ -0,0 +1,20 @@ +{ + "db_name": "PostgreSQL", + "query": "select username from profiles", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "username", + "type_info": "Varchar" + } + ], + "parameters": { + "Left": [] + }, + "nullable": [ + false + ] + }, + "hash": "989226d5c28e957f3bb8a763f9e7b3d435a130ac9c81b8bd902d184684a12a5c" +} diff --git a/.sqlx/query-dd6fdefdc01debb0f31ec08982b1b0ae551ea5b813840f9b69a73aeac919ec6d.json b/.sqlx/query-dd6fdefdc01debb0f31ec08982b1b0ae551ea5b813840f9b69a73aeac919ec6d.json new file mode 100644 index 0000000..dcd5051 --- /dev/null +++ b/.sqlx/query-dd6fdefdc01debb0f31ec08982b1b0ae551ea5b813840f9b69a73aeac919ec6d.json @@ -0,0 +1,20 @@ +{ + "db_name": "PostgreSQL", + "query": "select 1 as temp from profiles", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "temp", + "type_info": "Int4" + } + ], + "parameters": { + "Left": [] + }, + "nullable": [ + null + ] + }, + "hash": "dd6fdefdc01debb0f31ec08982b1b0ae551ea5b813840f9b69a73aeac919ec6d" +} diff --git a/src/server/mod.rs b/src/server/mod.rs index 616abef..af0397c 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -6,6 +6,5 @@ pub mod models; pub mod response; pub mod routes; pub mod state; -pub mod storage; pub mod supabase; pub mod ws; diff --git a/src/server/models.rs b/src/server/models.rs index b392b7f..f1e0592 100644 --- a/src/server/models.rs +++ b/src/server/models.rs @@ -1,16 +1,6 @@ use crate::strings::{UserId, UserName}; -use arcstr::ArcStr; use serde::Deserialize; -// TODO: avatar url -// learn how to allow user uploads to supabase assets -// learn how to delete stale user uploads -#[derive(Deserialize, Debug)] -pub struct Profile { - pub user_id: UserId, - pub username: UserName, -} - #[derive(Deserialize, Debug)] pub struct SupabaseUser { pub id: UserId, diff --git a/src/server/routes.rs b/src/server/routes.rs index ad287a9..bff0055 100644 --- a/src/server/routes.rs +++ b/src/server/routes.rs @@ -2,7 +2,7 @@ use super::errors::{AnyhowError, AnyhowResponse}; use super::models::CustomClaims; use super::response::AppResponse; use super::supabase::ExchangeOAuthCode; -use super::{auth, response, storage}; +use super::{auth, response}; use crate::actions::{ActionSubmission, ActionTag}; use crate::districts::DistrictName; use crate::game::Game; @@ -25,7 +25,6 @@ use http::{header, StatusCode}; use percent_encoding::utf8_percent_encode; use rand_core::SeedableRng; use serde::{Deserialize, Serialize}; -use sqlx::Acquire; use std::borrow::{Borrow, Cow}; use std::collections::{HashMap, HashSet}; use time::Duration; @@ -192,13 +191,15 @@ async fn get_oauth_callback( time::Duration::WEEK, )); - let url = if storage::profile(response.user.id).await.is_none() { - "/profile" - } else { - "/lobby" - }; + let mut tx = app.user_transaction(&cookies).await?; + let has_profile = sqlx::query!("select 1 as temp from profiles") + .fetch_optional(&mut *tx) + .await? + .is_some(); + tx.commit().await?; + + let url = if has_profile { "/profile" } else { "/lobby" }; - //response::ok(()) response::ok([(header::REFRESH, format!("0;url={}", url))]) } else { log::error!("no code verifier"); diff --git a/src/server/storage.rs b/src/server/storage.rs deleted file mode 100644 index 10f00a3..0000000 --- a/src/server/storage.rs +++ /dev/null @@ -1,10 +0,0 @@ -use super::models::Profile; -use crate::strings::UserId; - -pub async fn connect(_user_id: UserId) { - todo!() -} - -pub async fn profile(_user_id: UserId) -> Option { - return None; -} diff --git a/src/server/supabase.rs b/src/server/supabase.rs index fc48eb9..5bd7ae9 100644 --- a/src/server/supabase.rs +++ b/src/server/supabase.rs @@ -1,12 +1,9 @@ -use anyhow::bail; +use super::models::SupabaseUser; use arcstr::ArcStr; use reqwest::Response; use serde::{Deserialize, Serialize}; use std::env; use thiserror::Error; -use tower_cookies::Cookies; - -use super::models::{Profile, SupabaseUser}; #[derive(Clone, Debug)] pub struct SupabaseClient {