Every state your login screen has to handle
- Success: tokens plus the user object your app stores
- Wrong password: 401 with an error message to show
- Locked or unverified account: 423 or 403 with its own message
- Validation errors: 422 for an email in the wrong format
- Server errors: 500, to check your retry and error UI
- A slow network: a spinner that shows for two seconds, not 20 milliseconds
One endpoint, every outcome
Response variants let a single POST /auth/login return different responses depending on what is sent. Each variant has match conditions on a body field or query parameter, plus its own status code and body. The first variant that matches wins; if none match, the default response is returned.
password = "wrong" → 401 { "error": "InvalidCredentials" }
email = "locked@example.com" → 423 { "error": "AccountLocked" }
anything else → 200 { "accessToken": "{{$jwt.access:15m}}", … }Real tokens, real 401s
The success response can include real signed tokens with {{$jwt.access:15m}} and {{$jwt.refresh:7d}}. Endpoints protected with MockLab JWT auth then reject requests without a valid token, so logout-on-401 and token refresh get tested too.
You can also protect endpoints with a static Bearer token, an API key header or Basic auth if that is what your real API will use.
Call it from your app
const res = await fetch("https://api.mocklab.studio/mock/your-project/auth/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ email, password }),
});
if (res.status === 401) return showError("Email or password is incorrect");
if (res.status === 423) return showError("Your account is locked");
const { accessToken, refreshToken, user } = await res.json();Frequently asked questions
How do I simulate a wrong password?
Add a variant to your login endpoint that matches the body field password with the value you choose, for example "wrong", and give it a 401 status and error body.
Can I make the login slow?
Yes. Set a delay of up to 10 seconds on the endpoint to see your loading state the way users on a slow connection will.
Does it work from a phone or another computer?
Yes. Every endpoint is live at a public HTTPS URL, so it works from a browser, a simulator, a real device, Postman or CI.
Is MockLab free?
Yes, MockLab is free while it is in beta. No credit card required.
Stop waiting on the backend
Create your first endpoint in under a minute. It's live at a public URL as soon as you save it.