fix: lint issues in session_auth_axum example (#997)

* build: add common tasks

* fix: resolve check-style issues
This commit is contained in:
agilarity 2023-05-05 11:26:44 -04:00 committed by GitHub
parent f0f1c3144b
commit 15448765dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 16 deletions

View file

@ -1,3 +1,5 @@
extend = { path = "../cargo-make/common.toml" }
[tasks.build]
command = "cargo"
args = ["+nightly", "build-all-features"]

View file

@ -1,9 +1,7 @@
use std::collections::HashSet;
use cfg_if::cfg_if;
use leptos::*;
use serde::{Deserialize, Serialize};
use std::collections::HashSet;
cfg_if! {
if #[cfg(feature = "ssr")] {
@ -168,7 +166,9 @@ pub async fn login(
.ok_or("User does not exist.")
.map_err(|e| ServerFnError::ServerError(e.to_string()))?;
match verify(password, &user.password).map_err(|e| ServerFnError::ServerError(e.to_string()))? {
match verify(password, &user.password)
.map_err(|e| ServerFnError::ServerError(e.to_string()))?
{
true => {
auth.login_user(user.id);
auth.remember_user(remember.is_some());

View file

@ -13,7 +13,9 @@ impl TodoAppError {
pub fn status_code(&self) -> StatusCode {
match self {
TodoAppError::NotFound => StatusCode::NOT_FOUND,
TodoAppError::InternalServerError => StatusCode::INTERNAL_SERVER_ERROR,
TodoAppError::InternalServerError => {
StatusCode::INTERNAL_SERVER_ERROR
}
}
}
}

View file

@ -1,5 +1,4 @@
use crate::auth::*;
use crate::error_template::{ErrorTemplate, ErrorTemplateProps};
use crate::{auth::*, error_template::ErrorTemplate};
use cfg_if::cfg_if;
use leptos::*;
use leptos_meta::*;
@ -73,7 +72,8 @@ pub async fn get_todos(cx: Scope) -> Result<Vec<Todo>, ServerFnError> {
let pool = pool(cx)?;
let mut todos = Vec::new();
let mut rows = sqlx::query_as::<_, SqlTodo>("SELECT * FROM todos").fetch(&pool);
let mut rows =
sqlx::query_as::<_, SqlTodo>("SELECT * FROM todos").fetch(&pool);
while let Some(row) = rows
.try_next()
@ -111,11 +111,13 @@ pub async fn add_todo(cx: Scope, title: String) -> Result<(), ServerFnError> {
// fake API delay
std::thread::sleep(std::time::Duration::from_millis(1250));
match sqlx::query("INSERT INTO todos (title, user_id, completed) VALUES (?, ?, false)")
.bind(title)
.bind(id)
.execute(&pool)
.await
match sqlx::query(
"INSERT INTO todos (title, user_id, completed) VALUES (?, ?, false)",
)
.bind(title)
.bind(id)
.execute(&pool)
.await
{
Ok(_row) => Ok(()),
Err(e) => Err(ServerFnError::ServerError(e.to_string())),
@ -304,7 +306,10 @@ pub fn Todos(cx: Scope) -> impl IntoView {
}
#[component]
pub fn Login(cx: Scope, action: Action<Login, Result<(), ServerFnError>>) -> impl IntoView {
pub fn Login(
cx: Scope,
action: Action<Login, Result<(), ServerFnError>>,
) -> impl IntoView {
view! {
cx,
<ActionForm action=action>
@ -330,7 +335,10 @@ pub fn Login(cx: Scope, action: Action<Login, Result<(), ServerFnError>>) -> imp
}
#[component]
pub fn Signup(cx: Scope, action: Action<Signup, Result<(), ServerFnError>>) -> impl IntoView {
pub fn Signup(
cx: Scope,
action: Action<Signup, Result<(), ServerFnError>>,
) -> impl IntoView {
view! {
cx,
<ActionForm action=action>
@ -362,7 +370,10 @@ pub fn Signup(cx: Scope, action: Action<Signup, Result<(), ServerFnError>>) -> i
}
#[component]
pub fn Logout(cx: Scope, action: Action<Logout, Result<(), ServerFnError>>) -> impl IntoView {
pub fn Logout(
cx: Scope,
action: Action<Logout, Result<(), ServerFnError>>,
) -> impl IntoView {
view! {
cx,
<div id="loginbox">