How do I update my token when it expires and pass it to the global reference?
pub async fn kc_init_context() -> InfraResult<Arc<KcContext>> {
let kc_context = KcContext::new().await?; // connect an create token
let utc_now = Utc::now().timestamp();
if kc_context.claims.exp < utc_now {
println!("{:?}", "Expired token".to_string());
/// How create a new token and update global reference ?
/// kc_context = KcContext::new().await?;
}
// println!("{:?}", kc_context.claims);
Ok(Arc::new(kc_context))
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
dotenv().ok();
let kc_context = kc_init_context().await?;
HttpServer::new(move || {
App::new()
//.wrap_fn(|req, srv| counter_middleware(req, srv))
.app_data(data.clone())
.app_data(web::Data::new(graphql_scheme(kc_context.clone()).clone()))
.configure(graphql_routes)
.route("/ping", web::get().to(ping))
})
.bind(("127.0.0.1", 4042))?
.run()
.await
}
maybe using RwLock? I'm not sure how to do that