True
1201;
Score | 215
Matthew Okadinya Programmer @ Remotely
city Abuja, Nigeria
196
204
11
16
In Technology 4 min read
Bits & Pieces Part 1: They Said Passwordless Was Easy. They Lied. Here's How I Beat It Anyway.
<p><strong><em>Passwords are so 2004. Forget the endless string of forgotten passwords and “Reset your password” emails. In this first installment of our “Bits &amp; Pieces” series, we’re peeling back the curtain on how to build a truly seamless, production‑ready passwordless authentication flow—complete with magic links, SMTP wizardry, and rock‑solid database integration.&nbsp;</em></strong></p><p><br></p><p>Why am I doing this you might ask?</p><p><br></p><p>I want an app that feels like magic—one click and you’re in. No typing, no typos, no ‘forgot password?’ panic. Onward!</p><p>But isn’t that just convenience?”</p><p>Convenience is just the tip of the iceberg. Underneath, it’s about seamless onboarding. Imagine a SaaS platform that reduces the friction logins brings.</p><p><em><br></em></p><p><strong><em>The Hidden Perils of Passwords</em></strong></p><p><br></p><p>Users today juggle dozens of credentials—two‑thirds of Americans, for instance, admit to reusing the same password across multiple accounts, exponentially raising breach risk.</p><p>Weak, easily guessed passwords like “123456” remain the most common worldwide, used over 4.5 million times in leaked datasets. In 2021 alone, breaches exposed over 22 billion records—many traced back to compromised or reused passwords.&nbsp;</p><p>Requiring users to memorize or reset passwords not only creates friction but also fuels those poor habits—and ultimately undermines security and UX&nbsp;</p><p><br></p><p><strong><em>Magic Links: and Passwordless authentication: How They Work &amp; Security Trade‑Offs</em></strong></p><p><br></p><p>When a user submits their email, your backend generates a one‑time token, embeds it in a time‑limited link, and emails it via SMTP. Clicking the link validates the token, establishes a session, and logs them in—no password needed .</p><p>Short lifespans (e.g., 5–15 minutes) dramatically shrink the window for attackers to hijack a stolen link . Malicious sites can overlay invisible iframes or mimic your brand to trick users into clicking links they think are legitimate, always implement X‑Frame‑Options and clear branding in your email templates.</p><p>Some clients strip HTML links; including a plain‑text URL ensures deliverability but also gives attackers a copy‑paste vector—protect tokens with HTTPS and CSRF tokens on the endpoint.</p><p><br></p><p>Invalidating tokens immediately after first use, prevents replay attacks—store a “used” flag in your database adapter&nbsp;</p><p><strong><em>Let's hack this thing already.&nbsp;</em></strong></p><p><br></p><p>Well, first of all—a simple how-to on implementing passwordless authentication would suffice, right? Sure. Except that’s not how this really goes down.</p><p><br></p><p>I wanted to understand this inside-out. Not just slap a package together and hope the auth gods smile on me. No. I wanted to own this flow. Because if a user is going to click one link and get inside my app, that link better be bulletproof. Ironclad. Magical.</p><p>So I started where anyone would—Google. "passwordless authentication Next.js". The trail leads to Auth.js, formerly known as NextAuth.js. Ah. Rebranded. Just like a startup trying to sound cooler. Whatever. At least the docs exist.</p><p><br></p><p>First impression? It’s good. Maybe too good. Like that one CS major who turns in perfect assignments but you know they're pasting from somewhere. The magic link section is buried under “Email Provider”—like it doesn’t want to be found. Classic.</p><p>But I read it. Twice. Then once more. Here’s what clicked:</p><p>- You give it an email.</p><p>- It fires off a POST request to `/api/auth/signin/email`.</p><p>- Behind the scenes, a one-time-use token is generated.</p><p>- That token is embedded into a link and emailed via your chosen SMTP provider.</p><p>- User clicks. Token is validated. Boom—they're in.</p><p>But here's where reality smacks you in the face: email providers. Ah yes. You can’t just send email. This isn’t the Wild West. Every provider has opinions.</p><p>Four hours. That’s how long I spent spinning up Mailgun, Resend, SendGrid, and Brevo. One rejected me. Another ghosted. Two others wanted "domain verification." And then I found Postmark.</p><p>Clean. Straightforward. But—requires a verified work email. Not Gmail. Not Yahoo. A real domain. Classic gatekeeping.</p><p>Fine.</p><p>So I hacked the system. Spun up a domain in Google Cloud. Used their $300 free trial to register a real work email. Slapped that on Postmark. Verified. Approved. API key in hand. No payment needed. Production-grade email: unlocked.</p><p><br></p><p><strong>Now that’s a hack.</strong></p><p><em><br></em></p><p><strong><em>Next stop: Auth.js integration.</em></strong></p><p>Here's the plan:</p><p>1. Add Auth.js to our Next.js app.</p><p>2. Configure the email provider with Postmark using the API key.</p><p>3. Create the `/api/auth/[...nextauth].ts` file.</p><p>4. Use `providers: [EmailProvider({...})]` to hook in the magic link flow.</p><p>5. ENV file gets `POSTMARK_API_TOKEN`, `NEXTAUTH_SECRET`, and the rest.</p><p><br></p><p>Boom. From 0 to passwordless in under 100 lines of code.</p><p>But this isn’t just about setup. It’s about **user experience**. Clean, crisp emails. Branded links. Instant sessions. No janky redirects. No weird toast notifications. Just… magic.</p><p><br></p><p>And trust me, we’re just getting started.</p><p><br></p><p><br></p><p><br></p><p><br></p><p><br></p><p><br></p><p><br></p><p>Next up: **building a custom login UI**, session callbacks, edge cases like expired links, and how to make this thing feel like you’re *signing into the future</p>
audio player insight avatar on TwoCents
Bits & Pieces Part 1: They ...
By Matthew Okadinya 7 plays
0:00 / 0:00

|
Hi, I do this for fun but fun costs money these days, help me show you more walk arounds as we build together.
THIS INSIGHT HAS STARTED RECEIVING TIPS
5
views 156
8 share


Hi, it's Matthew, thanks for reading & listening to my insights.
I'm here to walk you through my thought process.

Other insights from Matthew Okadinya

Insights for you.
The first audio insight on TwoCents
100 views
6 upvotes
4 comments
What is TwoCents? ×
+