Extract apps/ai/src/auth.rs into crates/api-auth#3707
Conversation
Co-Authored-By: yujonglee <yujonglee.dev@gmail.com>
✅ Deploy Preview for hyprnote canceled.
|
✅ Deploy Preview for hyprnote-storybook canceled.
|
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Review1. CorrectnessMiddleware ordering is correct. In axum, the last The extension type bridging works. One cleanup needed: Cargo.lock has 3 unrelated stub packages ( Adding No functional regression overall - the auth logic, error codes, sentry context, and analytics extension insertion are all preserved. 2. API design - can we do better?The current Problem is (b) and (c) create unnecessary indirection. The crate introduces its own Suggested simpler API: Then
This makes Concretely, pub use hypr_supabase_auth::Claims;
pub const DEVICE_FINGERPRINT_HEADER: &str = "x-device-fingerprint";
#[derive(Clone)]
pub struct AuthState {
inner: SupabaseAuth,
required_entitlement: String,
}
pub async fn require_auth(
State(state): State<AuthState>,
mut request: Request,
next: Next,
) -> Result<Response, AuthError> {
// validate JWT, check entitlement, insert Claims
let claims = /* ... */;
request.extensions_mut().insert(claims);
Ok(next.run(request).await)
}And |
…s; remove Cargo.lock stubs Co-Authored-By: yujonglee <yujonglee.dev@gmail.com>
|
Devin is archived and cannot be woken up. Please unarchive Devin if you want to continue using it. |
5 similar comments
|
Devin is archived and cannot be woken up. Please unarchive Devin if you want to continue using it. |
|
Devin is archived and cannot be woken up. Please unarchive Devin if you want to continue using it. |
|
Devin is archived and cannot be woken up. Please unarchive Devin if you want to continue using it. |
|
Devin is archived and cannot be woken up. Please unarchive Devin if you want to continue using it. |
|
Devin is archived and cannot be woken up. Please unarchive Devin if you want to continue using it. |
Summary
Extracts the core auth middleware from
apps/ai/src/auth.rsinto a new standalone cratecrates/api-auth. The new crate is focused purely on JWT validation and entitlement checking:AuthState(takes a configurablerequired_entitlementinstead of hardcoding"hyprnote_pro")AuthErrorwith axumIntoResponserequire_authmiddleware (validates JWT, checks entitlement, insertsClaimsinto request extensions)The crate depends only on
hypr-supabase-auth+axum— no sentry, no analytics, no device fingerprint logic.apps/ai/src/auth.rsbecomes a thin adapter that layers a second middleware (sentry_and_analytics) which:Claimsfrom request extensions (set byrequire_auth)x-device-fingerprintheader directly from request headershypr_analytics::DeviceFingerprintandhypr_analytics::AuthenticatedUserIdinto extensions for downstream handlersAlso adds
Clonederive toClaimsandSubscriptionStatusinsupabase-auth(required byhttp::Extensions::insert).Updates since last revision
DeviceFingerprint/UserIdwrapper types fromapi-auth— the crate now only insertsClaimsinto extensions. Device fingerprint extraction is an app-level concern and stays inapps/ai/src/auth.rs.DEVICE_FINGERPRINT_HEADERconstant fromapi-auth— defined locally where needed (apps/ai/src/auth.rsandapps/ai/src/main.rs).tauri-plugin-cli2,tauri-plugin-db,tauri-plugin-export) that were artifacts from the dev machine.Review & Testing Checklist for Human
require_prois now split into tworoute_layercalls. Verify that request flow isrequire_auth→sentry_and_analytics→ handler (lastroute_layeris outermost in axum). This is the highest-risk behavioral change.AuthenticatedUserIdinsertion is now conditional:sentry_and_analyticsonly insertsAuthenticatedUserIdifClaimsis found in extensions. Sincerequire_authruns first and rejects unauthenticated requests, this should always be present — but confirm no edge case wheresentry_and_analyticsruns withoutrequire_authhaving succeeded.ClonetoClaims/SubscriptionStatus: Minor cross-cutting change tosupabase-auth. Confirm no downstream issues with these types now beingClone.Recommended test plan: Deploy to staging and verify that:
hyprnote_proentitlementDeviceFingerprintandAuthenticatedUserIdas beforeNotes
Link to Devin run: https://app.devin.ai/sessions/ddba5085a8b84ca3a404085c58cec62a
Requested by: @yujonglee