Implement Into<CaptureError> for the default server function error type (#4205)
* implement Into<CaptureError> for the server function error type * document the server function error type * fix tests
This commit is contained in:
1 parent
67f717647f
commit
f610c6b8c1
20 files changed
+316
-96
No files matched your search
@@ -196,7 +196,7 @@ pub async fn connect_to_database() -> SqlitePool {
|
||||
pub type Session =
|
||||
axum_session_auth::AuthSession<crate::auth::User, i64, SessionSqlitePool, sqlx::SqlitePool>;
|
||||
|
||||
pub async fn get_session() -> Result<Session, ServerFnError> {
|
||||
pub async fn get_session() -> ServerFnResult<Session> {
|
||||
extract::<Session, _>()
|
||||
.await
|
||||
.map_err(|_| ServerFnError::new("AuthSessionLayer was not found"))
|
||||
|
||||
@@ -75,7 +75,8 @@ fn app() -> Element {
|
||||
div {
|
||||
button { onclick: move |_| {
|
||||
async move {
|
||||
login().await.unwrap();
|
||||
login().await?;
|
||||
Ok(())
|
||||
}
|
||||
},
|
||||
"Login Test User"
|
||||
@@ -84,9 +85,9 @@ fn app() -> Element {
|
||||
div {
|
||||
button {
|
||||
onclick: move |_| async move {
|
||||
if let Ok(data) = get_user_name().await {
|
||||
user_name.set(data);
|
||||
}
|
||||
let data = get_user_name().await?;
|
||||
user_name.set(data);
|
||||
Ok(())
|
||||
},
|
||||
"Get User Name"
|
||||
}
|
||||
@@ -95,9 +96,9 @@ fn app() -> Element {
|
||||
div {
|
||||
button {
|
||||
onclick: move |_| async move {
|
||||
if let Ok(data) = get_permissions().await {
|
||||
permissions.set(data);
|
||||
}
|
||||
let data = get_permissions().await?;
|
||||
permissions.set(data);
|
||||
Ok(())
|
||||
},
|
||||
"Get Permissions"
|
||||
}
|
||||
@@ -107,20 +108,20 @@ fn app() -> Element {
|
||||
}
|
||||
|
||||
#[server]
|
||||
pub async fn get_user_name() -> Result<String, ServerFnError> {
|
||||
pub async fn get_user_name() -> ServerFnResult<String> {
|
||||
let auth = auth::get_session().await?;
|
||||
Ok(auth.current_user.unwrap().username.to_string())
|
||||
}
|
||||
|
||||
#[server]
|
||||
pub async fn login() -> Result<(), ServerFnError> {
|
||||
pub async fn login() -> ServerFnResult {
|
||||
let auth = auth::get_session().await?;
|
||||
auth.login_user(2);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[server]
|
||||
pub async fn get_permissions() -> Result<String, ServerFnError> {
|
||||
pub async fn get_permissions() -> ServerFnResult<String> {
|
||||
let method: axum::http::Method = extract().await?;
|
||||
let auth = auth::get_session().await?;
|
||||
let current_user = auth.current_user.clone().unwrap_or_default();
|
||||
|
||||
Reference in new issue
Block a user