비트베이크

Implementing SMS Authentication in T3 Stack (Next.js + tRPC) in 5 Minutes for Solo Devs (No Paperwork)

2026-05-30T01:02:20.475Z

Hooded figure with digital code for a face, representing digital security and development.

What is the most frustrating part of building a side project or an MVP? For many developers, it’s integrating SMS authentication. Most legacy SMS APIs require tedious paperwork, such as business registration and telecom certificates. For solo developers or startups trying to rapidly test an idea, this is a massive barrier to entry.

In this guide, we will learn how to implement SMS verification in just 5 minutes with zero paperwork using EasyAuth and the highly popular T3 Stack (Next.js + tRPC).

Why Choose EasyAuth?

  • Zero Paperwork: Sign up and use the API instantly without submitting any business documents.
  • Automatic Caller ID: No need to go through telecom verification to register a sender number.
  • Simple Architecture: Just two endpoints complete the flow: POST /send and POST /verify.
  • Cost-Effective: Only 15-25 KRW per message (compared to the standard 30-50 KRW), with 10 free credits provided upon signup.

Let’s dive into integrating EasyAuth into the T3 Stack.

1. Setting up the tRPC Router (Backend)

In the T3 Stack, we don't need to create standard API routes. Instead, we use tRPC mutations. First, create a new router file at src/server/api/routers/sms.ts.

import { z } from "zod";
import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";

// EasyAuth API Settings
const EASYAUTH_API_URL = "https://api.easyauth.co.kr";
const API_KEY = process.env.EASYAUTH_API_KEY!;

export const smsRouter = createTRPCRouter({
  // 1. Send OTP
  sendOtp: publicProcedure
    .input(z.object({ phoneNumber: z.string().min(10) }))
    .mutation(async ({ input }) => {
      const response = await fetch(`${EASYAUTH_API_URL}/send`, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          "Authorization": `Bearer ${API_KEY}`,
        },
        body: JSON.stringify({ to: input.phoneNumber }),
      });

      if (!response.ok) throw new Error("Failed to send SMS.");
      return { success: true, message: "OTP sent successfully." };
    }),

  // 2. Verify OTP
  verifyOtp: publicProcedure
    .input(z.object({ 
      phoneNumber: z.string(),
      code: z.string().length(6) 
    }))
    .mutation(async ({ input }) => {
      const response = await fetch(`${EASYAUTH_API_URL}/verify`, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          "Authorization": `Bearer ${API_KEY}`,
        },
        body: JSON.stringify({ 
          to: input.phoneNumber,
          code: input.code 
        }),
      });

      if (!response.ok) throw new Error("Invalid OTP code.");
      return { success: true, message: "Verification successful." };
    }),
});

Make sure to merge this router into your root API router in src/server/api/root.ts.

2. Frontend Integration

Now, let's create a Client Component in Next.js to handle the UI using tRPC hooks. We'll use standard React state for simplicity.

import { useState } from "react";
import { api } from "~/utils/api";

export default function SmsAuth() {
  const [phoneNumber, setPhoneNumber] = useState("");
  const [code, setCode] = useState("");
  const [isSent, setIsSent] = useState(false);

  const sendOtpMutation = api.sms.sendOtp.useMutation({
    onSuccess: () => setIsSent(true),
    onError: (err) => alert(err.message),
  });

  const verifyOtpMutation = api.sms.verifyOtp.useMutation({
    onSuccess: () => alert("Verification Complete!"),
    onError: (err) => alert(err.message),
  });

  const handleSend = () => sendOtpMutation.mutate({ phoneNumber });
  const handleVerify = () => verifyOtpMutation.mutate({ phoneNumber, code });

  return (
    <div>
      <h2>Phone Verification</h2>
      
      <div>
         setPhoneNumber(e.target.value)}
          disabled={isSent}
          className="flex-1 border p-2 rounded"
        /&gt;
        
          {isSent ? "Resend" : "Send OTP"}
        
      </div>

      {isSent &amp;&amp; (
        <div>
           setCode(e.target.value)}
            className="flex-1 border p-2 rounded"
          /&gt;
          
            Verify
          
        </div>
      )}
    </div>
  );
}

Conclusion

Without any complex paperwork or telecom reviews, we've successfully implemented SMS authentication using just two API endpoints (/send and /verify) combined with the power of the T3 Stack. EasyAuth handles all the complex backend logic out of the box, like storing OTP codes and checking expirations.

If you are building a toy project, a freelance gig, or a startup MVP, give EasyAuth a try. You can start testing instantly with 10 free credits provided upon signup, and scale your application effortlessly with an incredibly low cost of 15-25 KRW per message!

비트베이크에서 광고를 시작해보세요

광고 문의하기

다른 글 보기

2026-08-06T06:01:33.120Z

2026 GTX 개통 임박! A/B/C 노선 수혜지역 투자 가이드

2026년 GTX A/B/C 노선 개통이 임박하며 수도권 부동산 시장이 들썩이고 있습니다. GTX 노선별 개통 현황과 함께, 주요 수혜지역을 심층 분석하고 실거주 및 투자를 위한 현명한 전략과 유의점을 제시하여 성공적인 아파트 투자를 돕는 가이드입니다.

2026-08-05T06:01:33.825Z

2026 하반기 재건축 투자: 규제 완화 속 핵심 전략

2026년 하반기, 규제 완화 기대감 속 재건축 투자의 핵심 전략을 알아봅니다. 정부 정책 변화 분석, 유망 지역 선정 기준, 주의할 점, 그리고 성공적인 투자를 위한 전문가들의 조언까지, 2026 부동산 시장에서 기회를 잡을 방법을 제시합니다.

2026-08-04T06:01:37.246Z

2026 하반기 청약, 대출 금리 변화 활용 내집마련 필승 전략

2026년 하반기 청약 시장은 변화하는 대출 금리와 정책, 지역별 수급 상황에 따라 기회와 도전이 공존합니다. 이 글에서는 부동산 시장 동향과 주택담보대출 전략, 인기 청약 단지 분석, 청약 가점 및 특별공급 활용 팁 등 내 집 마련을 위한 필승 전략을 제시합니다. 철저한 준비와 현명한 판단으로 2026년 내 집 마련의 꿈을 이루세요.

2026-08-04T01:01:36.795Z

2026년 청약 성공 전략: 무주택자 내집마련 필승 가이드

2026년 무주택자의 내집마련 꿈을 위한 필승 청약 전략 가이드입니다. 청약 가점부터 특별공급 활용법, 현명한 대출 전략, 유망 단지 분석, 그리고 제도 변화까지 2026년 청약 성공을 위한 모든 정보를 담았습니다.

서비스

피드자주 묻는 질문고객센터

문의

비트베이크

레임스튜디오 | 사업자 등록번호 : 542-40-01042

경기도 남양주시 와부읍 수례로 116번길 16, 4층 402-제이270호

트위터인스타그램네이버 블로그