Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into sertschgi/main
Browse files Browse the repository at this point in the history
  • Loading branch information
jkelleyrtp committed Jan 21, 2025
2 parents 1d8af12 + 23d9178 commit 3675f7b
Show file tree
Hide file tree
Showing 52 changed files with 1,982 additions and 1,195 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ jobs:
- name: Build all flake outputs
run: om ci
- name: Ensure devShell has all build deps
run: nix develop -c cargo build -p dioxus-cli
run: nix develop -c cargo build -p dioxus-cli --features no-downloads

playwright:
if: github.event.pull_request.draft == false
Expand Down
109 changes: 104 additions & 5 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion example-projects/fullstack-hackernews/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ fn Preview(story: ReadOnlySignal<PreviewState>) -> Element {
active_story: Some(id),
} = story()
else {
return rsx! {"Hover over a story to preview it here"};
return rsx! {"Click on a story to preview it here"};
};

let story = use_server_future(use_reactive!(|id| get_story(id)))?;
Expand Down
14 changes: 0 additions & 14 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,3 @@ cargo run --example hello_world
[dog_app](./dog_app.rs) - Accesses dog API

[todomvc](./todomvc.rs) - Todo task list example

# TODO
Missing Features
- Fine-grained reactivity
- Refs - imperative handles to elements
- Function-driven children: Pass functions to make VNodes

Missing examples
- Shared state
- Root-less element groups
- Custom elements
- Component Children: Pass children into child components
- Render To string: Render a mounted virtualdom to a string
- Testing and Debugging
76 changes: 10 additions & 66 deletions examples/fullstack-auth/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,71 +192,15 @@ pub async fn connect_to_database() -> SqlitePool {
.unwrap()
}

pub struct Session(
pub axum_session_auth::AuthSession<
crate::auth::User,
i64,
axum_session_auth::SessionSqlitePool,
sqlx::SqlitePool,
>,
);

impl std::ops::Deref for Session {
type Target = axum_session_auth::AuthSession<
crate::auth::User,
i64,
axum_session_auth::SessionSqlitePool,
sqlx::SqlitePool,
>;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl std::ops::DerefMut for Session {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

#[derive(Debug)]
pub struct AuthSessionLayerNotFound;

impl std::fmt::Display for AuthSessionLayerNotFound {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "AuthSessionLayer was not found")
}
}

impl std::error::Error for AuthSessionLayerNotFound {}

impl IntoResponse for AuthSessionLayerNotFound {
fn into_response(self) -> Response {
(
http::status::StatusCode::INTERNAL_SERVER_ERROR,
"AuthSessionLayer was not found",
)
.into_response()
}
}

#[async_trait]
impl<S: std::marker::Sync + std::marker::Send> axum::extract::FromRequestParts<S> for Session {
type Rejection = AuthSessionLayerNotFound;

async fn from_request_parts(
parts: &mut http::request::Parts,
state: &S,
) -> Result<Self, Self::Rejection> {
axum_session_auth::AuthSession::<
crate::auth::User,
i64,
axum_session_auth::SessionSqlitePool,
sqlx::SqlitePool,
>::from_request_parts(parts, state)
pub type Session = axum_session_auth::AuthSession<
crate::auth::User,
i64,
axum_session_auth::SessionSqlitePool,
sqlx::SqlitePool,
>;

pub async fn get_session() -> Result<Session, ServerFnError> {
extract::<Session, _>()
.await
.map(Session)
.map_err(|_| AuthSessionLayerNotFound)
}
.map_err(|_| ServerFnError::new("AuthSessionLayer was not found"))
}
21 changes: 7 additions & 14 deletions examples/fullstack-auth/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
//! Run with:
//!
//! ```sh
//! dx build --features web
//! cargo run --features server
//! ```
#![allow(non_snake_case, unused)]

#[cfg(feature = "server")]
Expand Down Expand Up @@ -113,23 +106,23 @@ fn app() -> Element {
}
}

#[server(GetUserName)]
#[server]
pub async fn get_user_name() -> Result<String, ServerFnError> {
let session: crate::auth::Session = extract().await?;
Ok(session.0.current_user.unwrap().username.to_string())
let auth = auth::get_session().await?;
Ok(auth.current_user.unwrap().username.to_string())
}

#[server(Login)]
#[server]
pub async fn login() -> Result<(), ServerFnError> {
let auth: crate::auth::Session = extract().await?;
let auth = auth::get_session().await?;
auth.login_user(2);
Ok(())
}

#[server(Permissions)]
#[server]
pub async fn get_permissions() -> Result<String, ServerFnError> {
let method: axum::http::Method = extract().await?;
let auth: crate::auth::Session = extract().await?;
let auth = auth::get_session().await?;
let current_user = auth.current_user.clone().unwrap_or_default();

// lets check permissions only and not worry about if they are anon or not
Expand Down
Loading

0 comments on commit 3675f7b

Please sign in to comment.