Customers
The people who use your site or app — not the members of your organization.
Customers make their own accounts on your site, with an email and password. They never see the MINT panel; they only reach the models you made public for signed-in customers. Each project has its own customers: the same email in two projects is two separate accounts.
The sign-in widget
A ready-made sign-in and sign-up card — two lines of HTML.
<script src="https://mint-c5e1255519fc.herokuapp.com/public/widget.js" data-key="<project key>" async></script>
<div data-mint-login></div>Replace <project> with your project’s public name — the Public API page has the snippet ready. Every data-mint-login element becomes a card with Sign in and Create an account; once signed in it shows “Signed in as …” with a sign-out link. It follows the visitor’s light or dark setting and needs no styles of yours.
data-mode="signup"on the element opens it on Create your account.- Put the element on as many pages as you like; they all stay in step.
- The signed-in customer is remembered in their browser for 30 days.
MintAuth in your code
The widget gives your page’s scripts window.MintAuth.
| Use | Does |
|---|---|
await MintAuth.ready | Waits until the stored sign-in has been checked; gives the customer or null. |
MintAuth.user | The signed-in customer — { _id, name, email, phone } — or null. |
MintAuth.fetch(path, init) | Calls your public API as the customer: MintAuth.fetch('orders'). Same options as fetch. |
MintAuth.signIn(email, password) | Signs in from your own form. |
MintAuth.signUp({ name, email, password }) | Creates the account and signs in. |
MintAuth.signOut() | Signs out on this browser. |
MintAuth.onChange(cb) | Calls cb with the customer (or null) on every sign-in and sign-out; returns a function to stop. |
<script>
MintAuth.ready.then(async () => {
if (!MintAuth.user) return;
const res = await MintAuth.fetch('orders?sort=-createdAt');
const { doc } = await res.json();
renderOrders(doc);
});
MintAuth.onChange(user => document.body.classList.toggle('signed-in', !!user));
</script>Your own sign-in form
Skip the widget and call the API directly — from a mobile app, say.
| Request | Body → answer |
|---|---|
POST /auth/register | { name, email, password, phone? } → { token, customer }. Passwords need 8+ characters. |
POST /auth/login | { email, password } → { token, customer } |
GET /auth/me | The signed-in customer (send the token). |
PUT /auth/me | { name, phone } — the customer changes their details. |
POST /auth/logout-everywhere | Signs the customer out on every device. |
const res = await fetch('https://mint-c5e1255519fc.herokuapp.com/public/api/auth/login?apiKey=mint_pk_…', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email, password }),
});
const { token, customer, message } = await res.json();
// then: fetch('https://mint-c5e1255519fc.herokuapp.com/public/api/orders?apiKey=mint_pk_…', { headers: { Authorization: 'Bearer ' + token } })Tokens and signing out
- A token lasts 30 days, and only works for the project that issued it — never for the MINT panel or another project.
- Keep it like a password. The widget stores it in the browser’s localStorage; in an app, use its secure storage.
MintAuth.signOut()forgets it on this browser;logout-everywheremakes every token the customer has stop working.- Switching a customer off in the panel stops their tokens at once.
Managing customers
API → Customers lists everyone who signed up.
See each customer’s name, email, phone, when they joined and last signed in. Edit their name or phone, switch them off (they’re signed out and can’t sign in), or delete them. You never see or set their password, and customers can’t be added from the panel — they sign up themselves.
Troubleshooting
| Symptom | Why, and what to do |
|---|---|
| The card doesn’t appear | Check the script’s data-key is the project key from API → Keys, and that the page has a data-mint-login element. |
| “An account with this email exists” | They signed up before — sign in instead. |
| “This account has been switched off” | Switched off under Customers. Switch them on again. |
| Signed in, but API calls get 401 | Use MintAuth.fetch (or send the token) — plain fetch has no token. |
| “Too many attempts” | 40 sign-in attempts per 15 minutes per address. Wait and try again. |