Skip to content

Commit

Permalink
fix: add todos example to workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
cmackenzie1 committed Feb 19, 2025
1 parent b988cc9 commit 5053175
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ members = [
"torii-core",
"torii-storage-sqlite",
"torii-storage-postgres",
"examples/todos",
]
exclude = ["examples/todos"]
resolver = "2"

[workspace.package]
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "3"
services:
postgres:
image: postgres:17-alpine
Expand Down
10 changes: 4 additions & 6 deletions examples/todos/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use dashmap::DashMap;
use sqlx::{Pool, Sqlite};
use std::sync::Arc;
use torii_auth_email::EmailPasswordPlugin;
use torii_core::plugin::PluginManager;
use torii_core::{plugin::PluginManager, storage::Storage};
use torii_storage_sqlite::SqliteStorage;

mod routes;
Expand Down Expand Up @@ -44,12 +44,10 @@ async fn main() {
.await
.expect("Failed to migrate session storage");

let storage = Storage::new(user_storage.clone(), session_storage.clone());

let mut plugin_manager = PluginManager::new(user_storage.clone(), session_storage.clone());
plugin_manager.register(EmailPasswordPlugin::new());
plugin_manager
.setup()
.await
.expect("Failed to setup plugin manager");
plugin_manager.register(EmailPasswordPlugin::new(storage));
let plugin_manager = Arc::new(plugin_manager);

let app_state = AppState {
Expand Down
23 changes: 5 additions & 18 deletions examples/todos/src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use serde::Deserialize;
use serde_json::json;
use torii_auth_email::EmailPasswordPlugin;
use torii_core::{session::SessionId, User};
use torii_storage_sqlite::SqliteStorage;
use uuid::Uuid;

use crate::{
Expand Down Expand Up @@ -164,17 +165,10 @@ async fn sign_up_form_handler(
) -> impl IntoResponse {
let plugin = state
.plugin_manager
.get_plugin::<EmailPasswordPlugin>("email_password")
.get_plugin::<EmailPasswordPlugin<SqliteStorage, SqliteStorage>>("email_password")
.unwrap();

match plugin
.create_user(
state.plugin_manager.storage(),
&params.email,
&params.password,
)
.await
{
match plugin.create_user(&params.email, &params.password).await {
Ok(_) => (
StatusCode::OK,
Json(json!({ "message": "Successfully signed up" })),
Expand All @@ -201,17 +195,10 @@ async fn sign_in_form_handler(
) -> impl IntoResponse {
let plugin = state
.plugin_manager
.get_plugin::<EmailPasswordPlugin>("email_password")
.get_plugin::<EmailPasswordPlugin<SqliteStorage, SqliteStorage>>("email_password")
.unwrap();

match plugin
.login_user(
state.plugin_manager.storage(),
&params.email,
&params.password,
)
.await
{
match plugin.login_user(&params.email, &params.password).await {
Ok((_, session)) => {
let cookie = Cookie::build(("session_id", session.id.to_string()))
.path("/")
Expand Down

0 comments on commit 5053175

Please sign in to comment.