Skip to content

Commit

Permalink
Add login with token
Browse files Browse the repository at this point in the history
  • Loading branch information
kozabrada123 committed Aug 30, 2023
1 parent 6b35b3e commit 9cbf880
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/api/auth/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::errors::ChorusResult;
use crate::gateway::Gateway;
use crate::instance::{ChorusUser, Instance};
use crate::ratelimiter::ChorusRequest;
use crate::types::{GatewayIdentifyPayload, LimitType, LoginResult, LoginSchema};
use crate::types::{GatewayIdentifyPayload, LimitType, LoginResult, LoginSchema, User};

impl Instance {
/// Logs into an existing account on the spacebar server.
Expand Down Expand Up @@ -49,4 +49,25 @@ impl Instance {
);
Ok(user)
}

/// Logs into an existing account on the spacebar server, using only a token.
pub async fn login_account_with_token(&mut self, token: String) -> ChorusResult<ChorusUser> {
let object = self.get_user(token.clone(), None).await?;
let user_settings = User::get_settings(&token, &self.urls.api, &mut self.clone())
.await
.unwrap();
let mut identify = GatewayIdentifyPayload::common();
let gateway = Gateway::new(self.urls.wss.clone()).await.unwrap();
identify.token = token.clone();
gateway.send_identify(identify).await;
let user = ChorusUser::new(
Arc::new(RwLock::new(self.clone())),
token.clone(),
self.clone_limits_if_some(),
Arc::new(RwLock::new(user_settings)),
Arc::new(RwLock::new(object)),
gateway,
);
Ok(user)
}
}

0 comments on commit 9cbf880

Please sign in to comment.