I am creating a webapp with authentication using Rocket. To do this, I created a User
struct that implements FromRequest
. It takes the authorization header, which contains a JSON Web Token. I deserialize this token to obtain the payload, and then I query the user from the database. This means that the FromRequest
implementation needs a diesel::PgConnection
. In Rocket 0.3 this meant calling PgConnection::establish
, but with Rocket 0.4 we have access to a connection pool. Normally I would access this connection pool as follows:
fn get_data(conn: db::MyDatabasePool) -> MyModel {
MyModel::get(&conn)
}
However, within the impl block for FromRequest
I can not just add the conn
argument to the argument list of from_request
function. How do I access my connection pool outside of a request guard?