Face Guardian: Facial Recognition Authentication System
1 Software engineer, Singapore; cyrus@pastelero.ph
Abstract
Building an authentication system that prevents fake accounts before they exist. Using facial recognition and device fingerprinting to verify real humans, not just valid credentials.
Keywords: TypeScript; face-api.js; OAuth

The problem
Most authentication systems focus on keeping unauthorized users out. But they do nothing to stop someone from creating multiple fake accounts with different emails. By the time you detect fraud, the damage is done.
I wanted to flip the approach: prevent fraudulent accounts at registration, not after. If you could verify that each account belongs to a unique real person, the whole problem changes.
What I built
Face Guardian[1] uses facial recognition combined with device fingerprinting to verify identity at registration. The system stores face descriptors (not images) for privacy, detects spoofing attempts like photo replays, and integrates via OAuth so other apps can use it easily.
I also published it as an npm package[2] so developers can integrate facial authentication into their own projects.

The journey
The facial recognition uses face-api.js[3], which runs neural networks in the browser with TensorFlow.js: the Tiny Face Detector finds the face, and a ResNet-34 style network, with weights trained by dlib[4]'s author, turns it into a 128-number descriptor. The tricky part was making it work reliably in browsers with varying webcam quality and lighting conditions.
Tech stack
| Layer | Technology | Why |
|---|---|---|
| Frontend | Next.js[5] | React with SSR |
| Face Detection | face-api.js[3] | TensorFlow.js based, runs in browser |
| Auth Protocol | OAuth 2.0[6] | Standard protocol for integration |
| Fingerprinting | FingerprintJS[7] | Device identification |
| Hosting | Vercel[8] | Easy deploys with edge functions |
What building this taught me
1. Privacy by design changes everything
Storing face descriptors instead of actual images was a deliberate choice. Users are more comfortable when they understand their photos aren't saved anywhere. This also reduced storage costs. Descriptors still count as biometric data under GDPR[9], though, so they need the same care as photos.
// What gets stored (128-dimensional vector)
const faceDescriptor = new Float32Array(128)
// NOT the actual image
// Comparison uses Euclidean distance
const distance = faceapi.euclideanDistance(descriptor1, descriptor2)
const isMatch = distance < 0.6 // thresholdResources on face embeddings:
- FaceNet Paper[10] explaining face descriptors
- face-api.js Documentation[3]
2. Anti-spoofing is harder than recognition
Getting the AI to recognize a face is straightforward. Detecting whether that face is a real person or a photo held up to the camera? Much harder.
I implemented smile detection as a liveness check. The user has to smile during capture, which is difficult to fake with a static photo.
// Liveness check: detect smile
const expressions = detection.expressions
const isSmiling = expressions.happy > 0.25
if (!isSmiling) {
throw new Error('Please smile to verify liveness')
}Resources on anti-spoofing:
- Liveness Detection Techniques
- OWASP Authentication Cheat Sheet[11]
3. Lighting kills accuracy
The system works great in good lighting. In dim rooms or with backlighting, accuracy drops significantly. I spent a lot of time on preprocessing to normalize images, but there's only so much you can do when the input is bad.
4. Calling something OAuth does not make it OAuth
I shipped an authorization-code flow and described it as OAuth 2.0[6]. It borrows the
shape of OAuth and skips the parts that do the work. /api/request-token takes a code, looks the row up,
and hands back the token:
const { data } = await supabase
.from('tokens')
.select('token, expiration_date, created_at, is_revoked')
.eq('code', authorizationCode)
.single()There is no client authentication, so client_secret is never checked even though the column exists and
is generated for every app. There is no redirect_uri validation, no PKCE, and the code is never marked
used, so it is replayable until it expires. RFC 6749[12] requires the first, second and fourth, and current best practice, RFC 9700[13], requires PKCE for public clients and recommends it for the rest. What I built is a bearer code
lookup, and the standardized flow the npm package advertises is the one thing it does not implement.
// Simple integration with the npm package
import { FaceGuardian } from 'face-guardian'
const guardian = new FaceGuardian({
clientId: 'your-client-id',
redirectUri: 'https://yourapp.com/callback',
})
// Start authentication
await guardian.authenticate()Testing results
Held-up photos did not get past the smile check, and usability testing showed people liked the registration flow but not its error messages: when recognition failed, they could not tell why.
I used to quote a "100% blocked" figure here. It measured the wrong thing. /api/authenticate-face
accepts a userId from an unauthenticated request body, never compares a descriptor, never checks the
CAPTCHA (there is a TODO in that function saying so, and reasoning that the client already verified
it), and returns a working Supabase magic link for that account:
const { userId, captchaToken } = req.body
// TODO: Verify CAPTCHA token here if needed
const { data: authData } = await supabase.auth.admin.generateLink({
type: 'magiclink',
email: userData.email,
})
return res.status(200).json({ magicLink: authData.properties?.action_link })Anyone holding a user's UUID gets logged in as them, without presenting a face at all. So the replay number was true and irrelevant: I had hardened the camera and left a door open beside it. The deployment is retired now, but the lesson is the part worth keeping. I measured the attack I had thought about instead of enumerating the ways in.
The bigger realization
Building Face Guardian taught me that security and user experience are often in tension, but they don't have to be enemies. The best security is invisible security. Users shouldn't have to think about it.
What I would do differently
Add better user guidance during capture. Real-time feedback like "move closer" or "find better lighting" would prevent most failed attempts and reduce frustration.
Links
- npm: face-guardian[2]
- GitHub: face-guardian[1]
References
- Face Guardian. github.com. https://github.com/cyruspastelero/face-guardian ↑
- npm package. npmjs.com. https://www.npmjs.com/package/face-guardian ↑
- face-api.js. github.com. https://github.com/justadudewhohacks/face-api.js ↑
- dlib. dlib.net. http://dlib.net/ ↑
- Next.js. nextjs.org. https://nextjs.org/ ↑
- OAuth 2.0. oauth.net. https://oauth.net/2/ ↑
- FingerprintJS. fingerprint.com. https://fingerprint.com/ ↑
- Vercel. vercel.com. https://vercel.com/ ↑
- biometric data under GDPR. gdpr-info.eu. https://gdpr-info.eu/art-4-gdpr/ ↑
- FaceNet Paper. arxiv.org. https://arxiv.org/abs/1503.03832 ↑
- OWASP Authentication Cheat Sheet. cheatsheetseries.owasp.org. https://cheatsheetseries.owasp.org/cheatsheets/Authentication_Cheat_Sheet.html ↑
- RFC 6749. rfc-editor.org. https://www.rfc-editor.org/rfc/rfc6749.html ↑
- RFC 9700. rfc-editor.org. https://www.rfc-editor.org/rfc/rfc9700.html ↑
- TensorFlow.js. tensorflow.org. https://www.tensorflow.org/js