::: how to make this
To make a login system like NocNoc’s (using phone number + OTP), you’ll typically build a frontend + backend + SMS service. Here’s how to do it step-by-step:
✅ 1. Frontend (Login Page)
You can use React, Vue, or plain HTML/CSS. Example using HTML + basic JavaScript:
html<!-- login.html -->
<form id="loginForm">
<input type="tel" id="phoneNumber" placeholder="Enter phone number" required />
<button type="submit">Send OTP</button>
</form>
<form id="otpForm" style="display:none;">
<input type="text" id="otpCode" placeholder="Enter OTP" required />
<button type="submit">Verify OTP</button>
</form>
<script>
document.getElementById("loginForm").onsubmit = async (e) => {
e.preventDefault();
const phone = document.getElementById("phoneNumber").value;
await fetch("/send-otp", { method: "POST", headers: {"Content-Type": "application/json"}, body: JSON.stringify({ phone }) });
document.getElementById("otpForm").style.display = "block";
};
document.getElementById("otpForm").onsubmit = async (e) => {
e.preventDefault();
const otp = document.getElementById("otpCode").value;
const res = await fetch("/verify-otp", { method: "POST", headers: {"Content-Type": "application/json"}, body: JSON.stringify({ otp }) });
const data = await res.json();
if (data.success) alert("Login success!");
else alert("Invalid OTP");
};
</script>
✅ 2. Backend (Node.js Example)
Use Express + Twilio (for sending SMS):
js// server.js
const express = require("express");
const bodyParser = require("body-parser");
const session = require("express-session");
const twilio = require("twilio");
const app = express();
app.use(bodyParser.json());
app.use(session({ secret: "otpsecret", resave: false, saveUninitialized: true }));
const twilioClient = twilio("TWILIO_SID", "TWILIO_AUTH_TOKEN");
app.post("/send-otp", async (req, res) => {
const otp = Math.floor(100000 + Math.random() * 900000);
req.session.otp = otp;
await twilioClient.messages.create({
body: `Your OTP is ${otp}`,
from: "+1234567890", // your Twilio number
to: req.body.phone
});
res.json({ sent: true });
});
app.post("/verify-otp", (req, res) => {
const isValid = parseInt(req.body.otp) === req.session.otp;
res.json({ success: isValid });
});
app.listen(3000, () => console.log("Server running on http://localhost:3000"));
✅ 3. SMS Provider Options
- Twilio
- Firebase Phone Auth
- Line Notify API (for Thai users)
- NT SMS, AIS Business, SMSMKT – local Thai services
✅ 4. Security Considerations
- Use HTTPS (SSL)
- Limit OTP requests (throttle)
- Expire OTPs (e.g., 3 minutes)
- Store OTPs securely (server-side session, Redis, etc.)
Would you like a ready-made template using React + Node.js, or want to build this into your existing system? Let me know your preferred tech stack.
