AscendingCreations / AxumSession

Axum Session Management Libraries that use Sqlx
MIT License
148 stars 33 forks source link

Exclude session creation for certain routes #81

Closed j0lol closed 7 months ago

j0lol commented 7 months ago

I have certain routes that do not need to be linked to a session (one off webhooks), i would like to exclude them to not wastefully add rows to my database. How would I do this, if possible?

genusistimelord commented 7 months ago

Routes that need to be excluded from the system you would need to place them After the layer. Anytime you place stuff after the layers in the Router creation it makes it so those Routes don't have any layer other than those added after them.

for example i do mine like

 let app = Router::new()
        .route("/", get(root))
        .merge(main_routes())
        .merge(user_routes())
        .merge(view_routes())
        .merge(admin_routes())
        .merge(generator_routes())
        .fallback(site::handler_404)
        .layer(CatchPanicLayer::new())
        .layer(SetSensitiveHeadersLayer::new(once(header::AUTHORIZATION)))
        .layer(TraceLayer::new_for_http())
        .route("/reports/progress", post(progress_post))
        .layer(CompressionLayer::new())
        .layer(Extension(poll.clone()))
        .layer(middleware::from_fn(online_updater))
        .layer(Extension(server_state))
        .layer(
            AuthSessionLayer::<User, i64, SessionPgPool, PgPool>::new(Some(poll))
                .with_config(auth_config),
        )
        .layer(SessionLayer::new(session_store))
        .layer(CorsLayer::new().allow_origin(Any).allow_methods(Any))
        .nest_service("/static", get_service(ServeDir::new("static")))
        .with_state(system_state.clone());