Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesTaylor7 committed May 19, 2024
1 parent cb1c0fd commit 70ae570
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/server/middleware.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use http::{Request, Response};
use std::task::{Context, Poll};
use tower_cookies::{Cookie, Cookies};
use tower_cookies::{Cookies};
use tower_layer::Layer;
use tower_service::Service;

Expand Down
2 changes: 1 addition & 1 deletion src/server/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use rand_core::SeedableRng;
use serde::Deserialize;
use std::borrow::{Borrow, Cow};
use std::collections::{HashMap, HashSet};
use tower_cookies::{Cookie, CookieManagerLayer, Cookies};
use tower_cookies::{CookieManagerLayer, Cookies};
use tower_http::trace::TraceLayer;

pub fn get_router(state: AppState) -> Router {
Expand Down
8 changes: 3 additions & 5 deletions src/server/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ use super::ws::WebSockets;
use crate::server::supabase::SupabaseAnonClient;
use crate::server::ws;
use crate::strings::UserName;
use crate::strings::{AccessToken, OAuthCode, OAuthCodeVerifier, RefreshToken, SessionId, UserId};
use crate::strings::{AccessToken, RefreshToken, SessionId, UserId};
use crate::{game::Game, lobby::Lobby};
use serde::Deserialize;
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use tokio::sync::RwLock;
use tower_cookies::Cookies;

type PrivateCookieJar = Cookies;

fn new_arc_mutex<T>(item: T) -> Arc<std::sync::Mutex<T>> {
Arc::new(std::sync::Mutex::new(item))
}
Expand Down Expand Up @@ -46,7 +44,7 @@ impl Default for AppState {
}

impl AppState {
pub async fn session(&self, cookies: &PrivateCookieJar) -> Option<UserSession> {
pub async fn session(&self, cookies: &Cookies) -> Option<UserSession> {
let session_id = cookies.get("session_id")?;
self.logged_in
.read()
Expand All @@ -55,7 +53,7 @@ impl AppState {
.cloned()
}

pub async fn logout(&self, cookies: &PrivateCookieJar) -> anyhow::Result<()> {
pub async fn logout(&self, cookies: &Cookies) -> anyhow::Result<()> {
let session_id = cookies
.get("session_id")
.ok_or(anyhow::anyhow!("not actually logged in"))?;
Expand Down
2 changes: 1 addition & 1 deletion src/server/supabase.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::strings::{AccessToken, OAuthCode, OAuthCodeVerifier, RefreshToken, UserId};
use crate::strings::{AccessToken, RefreshToken, UserId};
use arcstr::ArcStr;
use reqwest::Response;
use serde::{Deserialize, Serialize};
Expand Down
16 changes: 0 additions & 16 deletions src/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ pub type UserId = ImmutableString<tags::UserId>;
pub type SessionId = ImmutableString<tags::SessionId>;
pub type AccessToken = ImmutableString<tags::AccessToken>;
pub type RefreshToken = ImmutableString<tags::RefreshToken>;
pub type OAuthCode = ImmutableString<tags::OAuthCode>;
pub type OAuthCodeVerifier = ImmutableString<tags::OAuthCodeVerifier>;

#[derive(PartialEq, Eq, Clone, Hash)]
pub struct ImmutableString<Tag> {
Expand Down Expand Up @@ -109,16 +107,6 @@ mod tags {
const SECRET: bool = true;
}

impl Tag for OAuthCode {
const NAME: &'static str = "oauth_code";
const SECRET: bool = false;
}

impl Tag for OAuthCodeVerifier {
const NAME: &'static str = "oauth_code_verifier";
const SECRET: bool = false;
}

#[derive(Debug, Eq, PartialEq, Clone, Hash)]
pub enum UserName {}
#[derive(Debug, Eq, PartialEq, Clone, Hash)]
Expand All @@ -129,8 +117,4 @@ mod tags {
pub enum AccessToken {}
#[derive(Debug, Eq, PartialEq, Clone, Hash)]
pub enum RefreshToken {}
#[derive(Debug, Eq, PartialEq, Clone, Hash)]
pub enum OAuthCode {}
#[derive(Debug, Eq, PartialEq, Clone, Hash)]
pub enum OAuthCodeVerifier {}
}

0 comments on commit 70ae570

Please sign in to comment.