Authentication
MaskAPI makes it easy to add authentication to your app.
Create multiple independent auth configurations each tied to its own table with custom login/signup logic and protected APIs. All setup happens in the UI.
📘 Before You Start
Ensure your project has a Database Connection:
- Select your project
- Go to the "Settings" tab
- Under "Project Global Configurations" section
- Add your database connection string in "Database Connection" field
- Toggle Active Database Authentication on
- Click "Save Changes" on the top of the page
Now you’re ready to create authentication configurations.
🧩 How to Create an Authentication Configuration
Create multiple auth configs (e.g. “Admin Panel” → admins
table, “Main App” → users
table):
- Select your project
- Go to the Settings tab
- Under Project DB Authentication Configurations section
- Click Create Auth Configuration button
- In General & Database tab enter a configuration name (e.g.
Admin Panel
) - Go to Database Table Configuration section
- Enter names for:
- Table: e.g.
admins
- Primary column: e.g.
id
- Credential column: e.g.
email
orusername
- Password column: e.g.
password
- Table: e.g.
- Click Create Configuration then Click Save Changes
Your new auth config appears in the list.
🔐 How to Configure Refresh Tokens
- Click Configure on your auth config card
- In General & Database tab scroll down to Refresh Tokens Management
- Toggle Enable Refresh Tokens on
- (Optional) update Refresh Token Expiry (days) time number if needed
- Click Validate to check your
refresh_tokens
table:- Create Table if missing
- Fix Schema if incomplete
- Click Save Changes
A valid refresh_tokens
table is required for refresh functionality.
🧪 How to Customize Login & Signup Logic
Each configuration has its own login and signup codes.
- Click Configure on your auth card
- Go to Authentication tab
- Click Login Configuration, edit the code,then Save
- Click Signup Configuration, edit the code,then Save
// Example: block inactive users
if (!user.isActive) throw new Error("Inactive account");
return true;
Pre‑built code is provided—customize only if you need extra checks.
🔒 How to Protect APIs with Middleware
You can decide which APIs require authentication per configuration.
- Click Configure on your auth card
- In Authentication tab, click Require Authentication APIs
- Check the requires middleware protection APIs
- Click Save update then Save Changes
Each API can be protected by only one auth configuration.
Other way to protect APIs is from studio after launch API in page over the Run buttons there is config button it shows only when you have it least one project auth config with it you can chose to protect API or not with any auth config if you have multiple ones.
🔌 Use Authentication Endpoints
Required Headers for All Requests:
x-mapi-key: your_project_key
x-mapi-auth-config-id: your_auth_config_id
Content-Type: application/json
Note: Replace your_project_key with your actual project's API key and your_auth_config_id with the ID of the authentication configuration you just set up you can find it in auth configuration modal in general settings section .
Login
POST https://mask.maskapi.dev/api/v1/auth/login
{ "credential": "user@example.com", "password": "password123" }
Signup
POST https://mask.maskapi.dev/api/v1/auth/signup
{ "credential": "new@example.com", "password": "password123", "confirmPassword":"password123", "name": "John" }
Refresh Token
POST https://mask.maskapi.dev/api/v1/auth/refresh
{ "refreshToken": "refresh_token_here..." }
Logout
POST https://mask.maskapi.dev/api/v1/auth/logout
Authorization: Bearer ACCESS_TOKEN
{ "refreshToken": "refresh_token_here..." }
For more examples you can find them in authentication config modal in API Examples tab
🚀 How to Call Your Protected APIs
Once APIs are protected, send the JWT accessToken as a Bearer token:
GET https://mask.maskapi.dev/api/v1/protected_api_path
Authorization: Bearer YOUR_ACCESS_TOKEN
x-mapi-key: your_project_key
// JavaScript (fetch)
fetch('https://mask.maskapi.dev/api/v1/protected_api_path', {
headers: {
'Authorization': `Bearer ${accessToken}`,
'x-mapi-key': 'YOUR_PROJECT_KEY',
}
})
.then(res => res.json())
.then(data => console.log(data));
That’s it—set up, secure, and consume your APIs with just a few clicks and headers! 🎉