Braine
  • Pricing
  • Enterprise
Book a demo
Contact us
Web & platform services
  • Web development

    High-performance websites and web apps — plus conversion-focused design, UX, and design systems.

  • Full-stack development

    End-to-end product builds from architecture through launch.

  • Rapid MVP development

    Launch-ready MVPs on a fixed timeline for client pitches.

  • Technical delivery partnerNew

    White-label engineering embedded behind your agency's brand.

Mobile development
  • Mobile app development

    Native and cross-platform apps built for scale.

  • iOS development

    Swift-powered apps for the Apple ecosystem.

  • Android development

    Kotlin and modern Android experiences.

  • Flutter development

    Single codebase, multiple platforms — with research-led product UX.

AI & integration
  • AI integration

    Embed AI workflows, smart search, assistants, and automation into products and operations.

  • Agentic AI developmentNew

    Autonomous AI agents and multi-step workflow systems.

  • Vibe coding remediationNew

    Audit and repair AI-generated codebases before they reach production.

  • API & platform integration

    Connect CRMs, payments, and third-party systems.

Agency partnership
  • Embedded delivery

    Your white-label technical team on demand.

  • Managed support

    Ongoing maintenance, QA, and deployments.

  • Portfolio delivery

    Ship client work faster without hiring in-house.

  • Book a strategy callNew

    Technical planning for launches and retainers.

Main navigation

Braine

Menu

  • Web & platform services
    • Web developmentHigh-performance websites and web apps — plus conversion-focused design, UX, and design systems.
    • Full-stack developmentEnd-to-end product builds from architecture through launch.
    • Rapid MVP developmentLaunch-ready MVPs on a fixed timeline for client pitches.
    • Technical delivery partnerNewWhite-label engineering embedded behind your agency's brand.
    Mobile development
    • Mobile app developmentNative and cross-platform apps built for scale.
    • iOS developmentSwift-powered apps for the Apple ecosystem.
    • Android developmentKotlin and modern Android experiences.
    • Flutter developmentSingle codebase, multiple platforms — with research-led product UX.
    AI & integration
    • AI integrationEmbed AI workflows, smart search, assistants, and automation into products and operations.
    • Agentic AI developmentNewAutonomous AI agents and multi-step workflow systems.
    • Vibe coding remediationNewAudit and repair AI-generated codebases before they reach production.
    • API & platform integrationConnect CRMs, payments, and third-party systems.
    Agency partnership
    • Embedded deliveryYour white-label technical team on demand.
    • Managed supportOngoing maintenance, QA, and deployments.
    • Portfolio deliveryShip client work faster without hiring in-house.
    • Book a strategy callNewTechnical planning for launches and retainers.
  • Portfolio
    • Featured workHighlighted projects from agency partners.
    • All case studiesBrowse the full portfolio with filters.
    • Browse by categoryFilter case studies by platform, industry, or deliverable.
    By deliverable
    • SaaS platformsSubscription products, dashboards, and B2B tools.
    • Mobile appsiOS, Android, and cross-platform client builds.
    • Web & platformsMarketing sites, portals, and ecommerce experiences.
    Journal
    • BlogInsights on delivery, tech, and growth.
    • Latest articlesRecent posts from the Braine journal.
    • Web & mobileEngineering notes for agency delivery teams.
  • Why Braine
    • TeamMeet the people behind delivery.
    • Our capabilitiesServices, tech stack, and AI under one roof.
    • Trusted partnersCreative and digital agencies we work with.
    Proof & answers
    • TestimonialsWhat agency partners say about working with us.
    • FAQProcess, pricing approach, tech stack, and timelines.
    • SupportHelp for new inquiries and active client work.
    Connect
    • Book intro callSchedule a walkthrough with our team.
    • ContactReach out about a project or partnership.
    • Email ussupport@braine.agency for written inquiries.
  • Pricing
  • Enterprise
Book a demo
Contact us
Home/Journal/Web Development
Journal
Web Development5 min read

```html

You're building a fantastic mobile app for a client using Flutter, or a blazing-fast web application with Next.

Piyas Talukder

Reviewed by Piyas Talukder · Founder LinkedIn

Published May 25, 2026

All articles
braine.agency/journalPreview
```html

```html

Article

JWTs: Stop Misusing Them & Secure Your Agency's APIs

You're building a fantastic mobile app for a client using Flutter, or a blazing-fast web application with Next.js. The UI is slick, the UX is intuitive, but are you really securing your APIs? All too often, I see agencies implementing JWTs incorrectly, leaving gaping security holes that are just waiting to be exploited. This isn't about just "using" JWTs; it's about using them *right*.

Understanding the JWT Landscape – and Its Pitfalls

JSON Web Tokens (JWTs) are a standard for securely transmitting information between parties as a JSON object. They're compact, self-contained, and can be cryptographically signed, making them ideal for authentication and authorization. However, their simplicity can be deceiving. The biggest mistake I see is treating JWTs as mere opaque tokens without understanding their inner workings and potential vulnerabilities.

Common Misconceptions & Dangerous Practices:

  • Storing Sensitive Data in the Payload: The JWT payload is only base64 encoded, *not* encrypted. Anyone can decode it and read the data. Never, ever store sensitive information like passwords, credit card details, or Personally Identifiable Information (PII) in the payload.
  • Using Weak Signing Algorithms: Don't even *think* about using HS256 (symmetric signing) in production. It's vulnerable to brute-force attacks. Always use RS256 (asymmetric signing) or ES256 (Elliptic Curve Digital Signature Algorithm) with strong key lengths.
  • Ignoring Token Expiration: JWTs should have a short lifespan. A token that's valid forever is a security nightmare. Implement proper expiration (exp claim) and refresh token mechanisms.
  • Lack of Proper Validation: Validate the signature, issuer (iss), audience (aud), and expiration time (exp) on the server side. Don't blindly trust the token.
  • Using JWTs for Session Management: This is a controversial point. While technically possible, JWTs aren't inherently designed for session management. Their stateless nature means you can't easily invalidate a JWT before its expiration. For applications where you *need* to be able to revoke access immediately (e.g., user logs out), consider using a traditional session-based approach *in conjunction* with JWTs for API authorization. This gives you the best of both worlds.

Implementing Robust JWT Authentication

Let's get practical. Here's how to implement a secure JWT authentication flow:

  1. User Authentication: The user provides their credentials (username/password, social login, etc.).
  2. Server-Side Verification: The server validates the credentials against the database.
  3. Token Generation: Upon successful authentication, the server generates a JWT. The payload should contain only necessary information, such as the user ID and roles.
  4. Token Signing: The server signs the JWT using a private key. Keep this key securely stored and never expose it.
  5. Token Transmission: The server sends the JWT back to the client (e.g., in the response body or as a cookie).
  6. Client-Side Storage: The client stores the JWT securely (e.g., in localStorage, sessionStorage, or a secure cookie). Be mindful of XSS vulnerabilities when using localStorage. Consider using HTTP-only cookies with the Secure and SameSite attributes for enhanced security.
  7. API Request Authorization: The client includes the JWT in the Authorization header of subsequent API requests (e.g., Authorization: Bearer ).
  8. Server-Side Validation: The server validates the JWT on each API request using the public key.
  9. Access Granted: If the JWT is valid, the server grants access to the requested resource.

Refresh Tokens: Extending Token Lifespan Securely

Short-lived JWTs are crucial for security, but they can be inconvenient for users. Refresh tokens provide a way to obtain new access tokens without requiring the user to re-authenticate.

Here's the flow:

  1. When the access token expires, the client sends the refresh token to the server.
  2. The server validates the refresh token.
  3. If the refresh token is valid, the server generates a new access token and a new refresh token.
  4. The server sends the new tokens back to the client.

Important considerations for refresh tokens:

  • Store refresh tokens securely on the server. Don't just store them in the JWT itself.
  • Implement refresh token rotation. Each time a refresh token is used, generate a new one. This limits the impact of a compromised refresh token.
  • Allow users to revoke refresh tokens. This is essential for security, especially if a user suspects their account has been compromised.

JWTs & AI: A Word of Caution

The integration of AI into applications is rapidly increasing. If you're using AI services in your application, ensure that you're not passing sensitive information in the JWT that could be inadvertently exposed to the AI model. For instance, if you're using an AI model for sentiment analysis of user comments, avoid including user IDs or other identifying information in the JWT that's sent along with the comment. This is particularly important when using third-party AI services, as you may not have complete control over how the data is processed and stored.

Protecting React, Next.js, and Flutter Apps

The framework you choose impacts how you implement JWT security. Here's a brief overview:

  • React: Use context or a state management library (Redux, Zustand) to store the JWT securely. Implement interceptors in your API client (e.g., Axios) to automatically include the JWT in the Authorization header.
  • Next.js: Leverage Next.js's API routes to handle authentication and token refresh. Store the JWT in HTTP-only cookies for enhanced security. Use server-side rendering (SSR) or static site generation (SSG) to avoid exposing the JWT in client-side JavaScript.
  • Flutter: Use the flutter_secure_storage package to store the JWT securely on the device. Implement interceptors in your HTTP client (e.g., http or dio) to automatically include the JWT in API requests.

FAQ

Q: What's the best way to store JWTs on the client side?

A: There's no single "best" way. HTTP-only cookies with the Secure and SameSite attributes are generally the most secure, as they are protected from XSS attacks. However, they can be more complex to implement. localStorage and sessionStorage are easier to use but are vulnerable to XSS. If you use them, implement robust input validation and sanitization to mitigate the risk. In Flutter, use flutter_secure_storage.

Q: How often should I rotate my signing keys?

A: Key rotation is a best practice. Rotate your signing keys at least every few months, or more frequently if you suspect a compromise. Implement a key rotation strategy that allows you to gracefully transition to the new key without disrupting existing users. This usually involves supporting multiple signing keys for a short period.

Q: What's the difference between authentication and authorization?

A: Authentication is verifying the user's identity (e.g., "Who are you?"). Authorization is determining what the user is allowed to do (e.g., "What can you access?"). JWTs are primarily used for authorization, but they rely on successful authentication.

Need help securing your APIs and building robust authentication flows? Contact us at Braine Agency. We have a proven track record of delivering secure and scalable software solutions for digital agencies. Check out our case studies to see how we've helped other agencies succeed.

Keep reading

Questions about this topic? We help agencies ship mobile, web, and AI-backed products — embedded in your workflow.

Contact usMore articles

About this article

Author
Braine Agency
Published
May 25, 2026
Category
Web Development
Reading time
5 min

Planning a similar initiative?

Tell us about scope and timeline — we'll reply with a clear next step.

Keep reading

  • UK Web Dev Partner: Beyond Price, Find Your True Fit
    Web Development

    UK Web Dev Partner: Beyond Price, Find Your True Fit

  • 8 Weeks to MVP: Ship Your Vision, Not Just a Spec
    Web Development

    8 Weeks to MVP: Ship Your Vision, Not Just a Spec

  • Scope MVPs That Get Funded: A Practitioner's Edge
    Web Development

    Scope MVPs That Get Funded: A Practitioner's Edge

Ready to build with Braine?

Braine Agency designs and ships high-converting websites, mobile apps, and AI-powered software. Explore what we do and see the work we've delivered.

Our servicesCase studiesBook a consultation

Your agency's technical delivery partner™

Services

Web & platform services
  • Web development
  • Full-stack development
  • Rapid MVP development
  • Technical delivery partner
Mobile development
  • Mobile app development
  • iOS development
  • Android development
  • Flutter development
AI & integration
  • AI integration
  • Agentic AI development
  • Vibe coding remediation
  • API & platform integration
Agency partnership
  • Embedded delivery
  • Managed support
  • Portfolio delivery
  • Book a strategy call

Navigation

Main

  • Home
  • Services
  • Featured work
  • Case studies
  • Pricing
  • Solutions
  • Braine Desk
  • Enterprise
  • Contact

Learn

  • Blog
  • Team
  • Testimonials
  • FAQ
Web & platform services
  • Web development
  • Full-stack development
  • Rapid MVP development
  • Technical delivery partner
Mobile development
  • Mobile app development
  • iOS development
  • Android development
  • Flutter development
AI & integration
  • AI integration
  • Agentic AI development
  • Vibe coding remediation
  • API & platform integration
Agency partnership
  • Embedded delivery
  • Managed support
  • Portfolio delivery
  • Book a strategy call
BraineAgency

© 2026 Braine. All rights reserved.

Privacy policyTerms of useSupportFAQ