Skip to content

Commit

Permalink
Sqlx
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesTaylor7 committed May 26, 2024
1 parent 8d06aae commit 42634ba
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 33 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
10 changes: 0 additions & 10 deletions src/server/models.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
17 changes: 9 additions & 8 deletions src/server/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
10 changes: 0 additions & 10 deletions src/server/storage.rs

This file was deleted.

5 changes: 1 addition & 4 deletions src/server/supabase.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down

0 comments on commit 42634ba

Please sign in to comment.