feat(core): add set_session to QbzCore and login_with_session to CoreBridge for OAuth
This commit is contained in:
2 files changed
+22
No files matched your search
@@ -109,6 +109,19 @@ impl<A: FrontendAdapter + Send + Sync + 'static> QbzCore<A> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Inject an already-authenticated session (e.g. from OAuth flow).
|
||||||
|
/// Emits a LoggedIn event so the rest of the system knows auth state changed.
|
||||||
|
pub async fn set_session(&self, session: UserSession) -> Result<(), CoreError> {
|
||||||
|
let client = self.client.read().await;
|
||||||
|
let client = client.as_ref().ok_or(CoreError::NotInitialized)?;
|
||||||
|
client.set_session(session.clone()).await;
|
||||||
|
self.emit(CoreEvent::LoggedIn {
|
||||||
|
session,
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Logout the current user
|
/// Logout the current user
|
||||||
pub async fn logout(&self) -> Result<(), CoreError> {
|
pub async fn logout(&self) -> Result<(), CoreError> {
|
||||||
let client = self.client.read().await;
|
let client = self.client.read().await;
|
||||||
|
|||||||
@@ -94,6 +94,15 @@ impl CoreBridge {
|
|||||||
.map_err(|e| e.to_string())
|
.map_err(|e| e.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Inject an already-authenticated session (for OAuth flow where we have
|
||||||
|
/// the UserSession from the legacy client but not email/password).
|
||||||
|
pub async fn login_with_session(&self, session: UserSession) -> Result<(), String> {
|
||||||
|
self.core
|
||||||
|
.set_session(session)
|
||||||
|
.await
|
||||||
|
.map_err(|e| e.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
/// Logout current user
|
/// Logout current user
|
||||||
pub async fn logout(&self) -> Result<(), String> {
|
pub async fn logout(&self) -> Result<(), String> {
|
||||||
self.core.logout().await.map_err(|e| e.to_string())
|
self.core.logout().await.map_err(|e| e.to_string())
|
||||||
|
|||||||
Reference in new issue
Block a user