chore: merge with main

This commit is contained in:
Fu Zi Xiang 2023-11-06 23:54:36 +08:00
parent 119156a3a9
commit c029759573
No known key found for this signature in database
2 changed files with 21 additions and 24 deletions

View File

@ -1,14 +0,0 @@
{
"db_name": "PostgreSQL",
"query": "\n UPDATE auth.users\n SET role = 'supabase_admin', email_confirmed_at = NOW()\n WHERE id = $1\n ",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Uuid"
]
},
"nullable": []
},
"hash": "141454ccce32ab6abd9fba21292d6290b7d73425f82bcf63ad4a0bd6959047d5"
}

View File

@ -217,32 +217,43 @@ async fn setup_admin_account(
match res_resp { match res_resp {
Ok(resp) => match resp { Ok(resp) => match resp {
gotrue_entity::dto::SignUpResponse::Authenticated(_) => { gotrue_entity::dto::SignUpResponse::Authenticated(resp) => {
tracing::info!("Admin user already authenticated"); tracing::info!(
"Admin user already created and authenticated at {:?}",
resp.user.email_confirmed_at
);
Ok(()) Ok(())
}, },
gotrue_entity::dto::SignUpResponse::NotAuthenticated(user) => { gotrue_entity::dto::SignUpResponse::NotAuthenticated(user) => {
let user_id = user.id.parse::<uuid::Uuid>().unwrap(); let user_id = user.id.parse::<uuid::Uuid>().unwrap();
sqlx::query!( let result = sqlx::query(
r#" r#"
UPDATE auth.users UPDATE auth.users
SET role = 'supabase_admin', email_confirmed_at = NOW() SET role = 'supabase_admin', email_confirmed_at = NOW()
WHERE id = $1 WHERE id = $1
"#, "#,
user_id
) )
.bind(user_id)
.execute(pg_pool) .execute(pg_pool)
.await .await
.context("failed to update the admin user")?; .context("failed to update the admin user")?;
assert_eq!(result.rows_affected(), 1);
Ok(()) Ok(())
}, },
}, },
Err(err) => match (err.code, err.msg.as_str()) { Err(err) => {
(400, "User already registered") => { if let app_error::gotrue::GoTrueError::Internal(err) = err {
tracing::info!("Admin user already registered"); match (err.code, err.msg.as_str()) {
Ok(()) (400, "User already registered") => {
}, tracing::info!("Admin user already registered");
_ => Err(err.into()), Ok(())
},
_ => Err(err.into()),
}
} else {
Err(err.into())
}
}, },
} }
} }