Add Secure Login to YourAI App with OwlAuth
AI apps hold a lot of value: private chats, uploaded documents, API keys for model providers, and often billing. That makes their user accounts a target. The attacks are the same ones that hit any web app, mostly credential stuffing and weak passwords. The good news is that strong login is a solved problem, and you do not have to build it yourself. This guide shows the safe path with OwlAuth.
Why Does an AI App Need Strong Login?
Because the account is the front door to everything the app can do. If an attacker signs in as your user, they can read private conversations, pull data the AI has access to, and spend money on model calls in the user's name. Most break ins do not use clever tricks. They reuse passwords that leaked from other sites, which is why blocking breached passwords is one of the highest value things you can do.
How Do You Set Up OwlAuth?
Install the library and create an auth manager. OwlAuth stays out of your framework and works with PostgreSQL or MongoDB. Install it first:
npm install @restingowlorg/owlauth
import { createAuthManager, PostgresAdapter } from "@restingowlorg/owlauth";
const auth = await createAuthManager({
adapter: new PostgresAdapter({
postgresUrl: process.env.POSTGRES_URL,
userTableName: "users",
magicLinkTableName: "magic_links",
}),
authTypes: ["credentials", "magicLink"],
blockedPasswords: ["your-app-name", "company-name"],
pwnedPasswordFailClosed: true, // reject known breached passwords
});
Two options here do a lot of work. pwnedPasswordFailClosed checks new passwords against the Have I Been Pwned database using k anonymity, so a password that has appeared in a breach is refused. blockedPasswords lets you ban obvious guesses like your product name. Password strength is also checked for you.
How Do You Sign Up and Log In Users?
Signup and login are single calls that return a clear result you can check. Weak or breached passwords are rejected at signup automatically.
// Sign up: a breached or weak password is refused here
const signup = await auth.credentials.signup(
"user@example.com",
"engineer01",
"CorrectHorseBatteryStaple!2026",
);
if (signup.success) {
console.log("created", signup.data.user.email);
}
// Log in
const login = await auth.credentials.login(
"user@example.com",
"CorrectHorseBatteryStaple!2026",
);
if (!login.success) {
// login.httpCode and login.message tell you why
}
Every call returns a consistent result with a success flag, an httpCode, and a message, so you always know what happened. Sensitive fields such as passwords and tokens are masked in the library's audit logs.
How Do You Add Passwordless Magic Links?
Magic links let users sign in with a single use link sent to their email, with no password to steal or reuse. They are a great fit for AI apps that want a low friction signup. OwlAuth handles the token safety for you: request a link, verify it, then consume it so it cannot be used twice.
// 1. Request a link and email it to the user
const requested = await auth.magicLink.request("user@example.com");
if (requested.success) {
const token = requested.data;
// ...email a URL containing this token...
// 2. When the user clicks, verify then consume the token
const verified = await auth.magicLink.verify(token);
const consumed = await auth.magicLink.consume(token);
}
For the ideas behind magic links, see our guide on passwordless magic links.
Secure Login Checklist for AI Apps
- 1Block breached passwords at signup and password change with the Have I Been Pwned check.
- 2Ban obvious guesses such as your product or company name.
- 3Offer passwordless magic links for low friction, safer sign in.
- 4Hash passwords with a strong, slow algorithm, which OwlAuth does for you.
- 5Return clear results and handle failed logins without leaking why an account does or does not exist.
- 6Keep audit logs with sensitive fields masked.
- 7Add a second step for sign in with multi factor authentication for extra protection.
To go further, add a second factor at sign in. See our guide on multi factor authentication, and store passwords well with the ideas in password hashing.
npm install @restingowlorg/owlauth and add the signup and login above. Securing the agent side of your AI app too? See how to revoke an AI agent's access and least privilege for AI agents.