Skip to content
tezvyn:

Authentication

78 bites tagged Authentication — interview questions with model answers, and 60-second explainers.

Node.js & Express1 min read

How to authenticate WebSocket connections using JWTs?

Client sends JWT on connection, server validates via middleware, socket is attached to user. WebSocket auth patterns and middleware understanding.

React & Next.js1 min read

Session auth in Next.js with API routes and middleware

Login route sets a signed httpOnly cookie, middleware validates the session at the edge and redirects, server components read the session. Session flow on a hybrid framework.

React & Next.js1 min read

localStorage vs httpOnly cookie for auth tokens

LocalStorage is JS-readable so XSS steals it; httpOnly cookies are JS-invisible blocking XSS theft but exposed to CSRF, mitigated by SameSite and tokens. Token storage security trade-offs.

React Native1 min read

Axios interceptors for auth headers

Interceptors are hooks that run before requests or after responses, centralizing concerns like auth, logging, and token refresh. cross-cutting request handling. attaching the token manually in every call site.

React Native1 min read

Structuring an auth flow in React Navigation

Conditionally render an auth stack versus app stack from state, not navigate calls; store token; let state drive screens. navigator structuring around auth state. navigating between stacks manually instead of swapping them.

Python & FastAPI2 min read

OAuth2 social login with your own JWT

A login endpoint redirects to the provider with a state param, a callback exchanges the code for the provider token, you fetch the user profile, upsert the local user, then mint your own JWT. The authorization code flow end to end.

Python & FastAPI1 min read

Secure refresh token flow for access renewal

Short-lived access token, longer-lived refresh token stored server-side, a refresh endpoint that validates and rotates the refresh token issuing a new pair. Designing the access plus refresh token pattern.

Python & FastAPI1 min read

Revoking stateless JWTs on logout

A server-side denylist of revoked token IDs checked per request, or short-lived access tokens paired with revocable refresh tokens. Reconciling stateless tokens with real revocation.

Product Strategy1 min read

Public API design versus internal API design

Public needs strict versioning, long deprecation, scoped auth like OAuth and API keys, and polished docs; internal can move faster. public APIs are long-lived contracts.

Node.js & Express1 min read

JWT login and protected route flow in Express

Verify credentials, sign a JWT, client stores and sends it (Authorization header or httpOnly cookie), middleware verifies signature on protected routes. end-to-end JWT auth flow and storage tradeoffs.

Node.js & Express2 min read

JWT storage: localStorage versus HttpOnly cookie

LocalStorage is JS-readable so XSS steals the token; HttpOnly cookies resist XSS theft but reintroduce CSRF, mitigated by SameSite plus CSRF tokens. Reasoning about XSS/CSRF trade-offs in token storage.

Node.js & Express1 min read

Explaining and preventing CSRF in Express

CSRF abuses a victim's ambient cookies to forge state-changing requests; the server issues an unpredictable token tied to the session, embeds it in forms, and validates it… Understanding CSRF and the synchronizer-token pattern.

Node.js & Express1 min read

Securing Express with Passport local strategy

Configure LocalStrategy with a verify callback, call passport.authenticate as route middleware, and set up serializeUser/deserializeUser for sessions. practical Passport.js wiring.

Node.js & Express1 min read

Session-based versus token-based authentication

Sessions store server-side state with a cookie id, tokens carry self-contained claims with no server store, weigh revocation versus scalability, especially across services. auth architecture trade-offs.

Node.js & Express1 min read

JWT structure and how the signature works

Name header, payload, and signature, note the first two are base64url-encoded not encrypted, explain the signature is computed over header and payload with a secret to detect tampering. understanding of JWT anatomy.

Node.js & Express1 min read

Authentication versus authorization in Express

Authentication proves who you are, authorization decides what you may do, authentication happens first. a core security vocabulary distinction.

Node.js & Express1 min read

Write a JWT authentication middleware

Read the header, strip Bearer, jwt.verify with the secret, set req.user and next(), else send 401. extracting a Bearer token, verifying it, and gating access. calling next() after sending 401, or trusting an unverified token.

Node.js & Express1 min read

Custom API key auth middleware

Read the header from req, on missing or invalid send res.status(401) and return, on valid call next, mount before protected routes. writing middleware with the req, res, next contract.

Monitoring & SRE2 min read

Defining SLIs and an SLO for an auth service?

Pick user-centric SLIs like login availability and latency, measure good over valid events at the right boundary, then set an achievable SLO with a window. Translating user needs into measured reliability.

Monitoring & SRE2 min read

Proposing availability and latency SLIs for an auth API

Availability as the ratio of successful valid requests; latency as the fraction served under a threshold; measure at the edge from the user's view. Designing measurable, user-centric SLIs.

iOS & Swift1 min read

Why store auth tokens in Keychain, not UserDefaults?

UserDefaults is an unencrypted plist readable from backups and on jailbroken devices; use Keychain Services, which stores encrypted items with access control; save with SecItemAdd and read with… secure credential storage.

Flutter & Dart1 min read

Auth-protected routes via GoRouter redirect

A top-level redirect reads auth state, sends unauthenticated users to login, sends logged-in users away from login, and uses refreshListenable to re-evaluate on auth change. guarding routes with redirect.

Android & Kotlin2 min read

How do you implement OAuth2 token refresh with Retrofit Authenticator?

Implement authenticate() with a blocking refresh, new Request with new token, Mutex for parallel 401s. Distinguishing Authenticator from Interceptor for 401 retry and sync.

Vue, Angular & Svelte2 min read

Explain navigation guards and provide an auth use case

Guards are global, per-route, or in-component hooks; returning false cancels, a route object redirects; use auth on /dashboard. Grasp of routing lifecycle interception. Calling them listeners without mentioning returns.

Get Authentication bites daily.

Five a day, five minutes, offline. With quizzes so it sticks.

Open testing — you’ll join as an early tester.