Skip to content

Nested Async/Await in guards #2202

Discussion options

You must be logged in to vote

For this to work, Rust would need to support async closures, which it currently does not. So, don't use a closure:

#[rocket::async_trait]
impl<'r> FromRequest<'r> for Item<'r> {
    type Error = ();

    async fn from_request(request: &'r Request<'_>) -> request::Outcome<Self, Self::Error> {
        let cookie = request.cookies().get("refresh_token");
        match cookie {
            Some(cookie) => {
                let user = crypto::verify_refresh_token(cookie.value());
                match user {
                    Ok(user) => {
                        let db = try_outcome!(request.guard::<&State<PrismaClient>>().await);
                        let user = db.inner()

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by samchouse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants