Yorrick Elzinga
09/24/2025, 8:01 PMAsk Inkeep
09/24/2025, 8:01 PMpermit support automation2
09/24/2025, 8:01 PMAsk Inkeep
09/24/2025, 8:01 PMnpm install permit-js
or
yarn add permit-js
Backend Configuration
Create a backend route for the login endpoint :
permit.elements.loginAs
This function takes two parameters: the current user ID/email and the tenant .
Frontend Configuration
In your frontend, import Permit and set up the login function :
permit.elements.login
You need to pass the login URL (your backend endpoint) and specify the login method (cookie, bearer token, or HTTP security header) .
Common Issues to Check
1. *Missing /login_elements request* - If you don't see this request in your Network tab after login, the login method isn't implemented correctly (2) .
2. *404/422 errors* - Make sure you're sending the correct response format from your backend :
res.status(200) .send(ticket.content) ; // CORRECT: sending ticket.content
3. *CORS issues* - Configure your server to allow requests from your frontend :
res.header("Access-Control-Allow-Origin", "<http://localhost:3001>") ; // update to match the domain you will make the request from
res.header("Access-Control-Allow-Credentials", "true") ;
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization, X-Permit-User-Key") ;
4. *Cookie blocked* - Check if third-party cookies are enabled in your browser settings .
5. *401 Unauthorized on /me endpoint* - This indicates the user isn't logged in, session expired, or invalid environment key/id . Look for the permit_session cookie in the Request Headers .
To help debug further, check the Developer Tools Network tab for the /login_elements and /me requests .Ask Inkeep
09/24/2025, 8:02 PMYorrick Elzinga
09/24/2025, 8:06 PMYorrick Elzinga
09/24/2025, 8:11 PMYorrick Elzinga
09/24/2025, 8:16 PMAsk Inkeep
09/24/2025, 8:16 PMAsk Inkeep
09/24/2025, 8:16 PMloginAs is a *server-side* method, not a client-side method. Here's the correct implementation:
Server-side (Backend)
The loginAs method exists on the server-side Permit instance (1) :
const { Permit } = require("permitio") ;
const permit = new Permit({token: "<YOUR_API_KEY>", ...}) ;
// In your backend route
const ticket = await permit.elements.loginAs({userId: user_key, tenantId: TENANT}) ;
For Python :
from permitio import Permit
permit = Permit(token="<YOUR_API_KEY>", ...)
# In your backend route
ticket = await permit.elements.login_as(USER, TENANT)
Client-side (Frontend)
On the frontend, you use the login method from permit-js :
permit.elements.login({
loginUrl: '<https://your_app_url.com/login_cookie>',
tenant: 'your_tenant_key',
loginMethod: LoginMethod.cookie
})
The TypeScript error you're seeing suggests you're trying to use loginAs on the frontend Permit instance, but it only exists on the backend SDK. The frontend only has the login method available .Ask Inkeep
09/24/2025, 8:16 PMYorrick Elzinga
09/24/2025, 8:19 PMAsk Inkeep
09/24/2025, 8:19 PMAsk Inkeep
09/24/2025, 8:19 PMconst permit = new Permit({
token: "[YOUR_API_KEY]",
pdp: "<http://localhost:7766>"
}) ;
(2)
Replace [YOUR_API_KEY] with the actual key you copied from the dashboard . Keep this key secure and never expose it in client-side code.Ask Inkeep
09/24/2025, 8:19 PMOr Weis
09/24/2025, 8:20 PMYorrick Elzinga
09/24/2025, 8:22 PMOr Weis
09/24/2025, 8:23 PMYorrick Elzinga
09/24/2025, 8:25 PMYorrick Elzinga
09/24/2025, 8:25 PMOr Weis
09/24/2025, 8:26 PMYorrick Elzinga
09/24/2025, 8:27 PMOr Weis
09/24/2025, 8:28 PMYorrick Elzinga
09/24/2025, 8:28 PMOr Weis
09/24/2025, 8:28 PMYorrick Elzinga
09/24/2025, 8:29 PMYorrick Elzinga
09/24/2025, 8:29 PMOr Weis
09/24/2025, 8:30 PMOr Weis
09/24/2025, 8:30 PMYorrick Elzinga
09/24/2025, 8:31 PMOr Weis
09/24/2025, 8:31 PMYorrick Elzinga
09/24/2025, 8:32 PMOr Weis
09/24/2025, 8:34 PMYorrick Elzinga
09/24/2025, 8:35 PMOr Weis
09/24/2025, 8:36 PMYorrick Elzinga
09/24/2025, 8:37 PMOr Weis
09/24/2025, 8:39 PMOr Weis
09/24/2025, 8:40 PMYorrick Elzinga
09/24/2025, 8:41 PMYorrick Elzinga
09/24/2025, 8:41 PMYorrick Elzinga
09/24/2025, 8:41 PMOr Weis
09/24/2025, 8:42 PMYorrick Elzinga
09/24/2025, 8:43 PMOr Weis
09/24/2025, 8:44 PMOr Weis
09/24/2025, 8:45 PMOr Weis
09/24/2025, 8:45 PMYorrick Elzinga
09/24/2025, 8:46 PMYorrick Elzinga
09/24/2025, 8:46 PMOr Weis
09/24/2025, 8:47 PMYorrick Elzinga
09/24/2025, 8:48 PMOr Weis
09/24/2025, 8:50 PMYorrick Elzinga
09/24/2025, 8:54 PMThomas
09/24/2025, 8:55 PMThomas
09/24/2025, 8:55 PMYorrick Elzinga
09/24/2025, 8:56 PMThomas
09/24/2025, 8:57 PMsession: {
strategy: 'jwt',
},Thomas
09/24/2025, 8:57 PMThomas
09/24/2025, 9:01 PMThomas
09/24/2025, 9:01 PMThomas
09/24/2025, 9:08 PMThomas
09/24/2025, 9:09 PMCould i keep the login flow using nextauth, and create a jwt when logging in and use that?Yes, I think that will be the easiest. you can use the
jsonwebtoken libraryThomas
09/24/2025, 9:09 PMjoseYorrick Elzinga
09/24/2025, 9:13 PMYorrick Elzinga
09/24/2025, 9:26 PMYorrick Elzinga
09/24/2025, 9:26 PMThomas
09/24/2025, 9:33 PMYorrick Elzinga
09/24/2025, 9:37 PMYorrick Elzinga
09/24/2025, 9:37 PMYorrick Elzinga
09/24/2025, 9:38 PMYorrick Elzinga
09/24/2025, 9:39 PM'use client';
import { useEffect } from 'react';
import permit, { LoginMethod } from '@permitio/permit-js';
export default function PermitLogin() {
useEffect(() => {
async function loginWithPermit() {
try {
const res = await fetch('/api/user-jwt');
const data = await res.json();
if (!data.token) {
console.error('No JWT found');
return;
}
await permit.elements.login({
// loginMethod: LoginMethod.frontendOnly,
// userJwt: data.token,
// tenant: 'aichatbot',
// envId: '4e9eb067dd114f51950886a823c76c4b',
loginMethod: LoginMethod.cookie,
loginUrl: '<http://localhost:3000/api/user-jwt>',
tenant: 'aichatbot',
});
console.log('Permit login success');
} catch (err) {
console.error('Permit login error', err);
}
}
loginWithPermit();
}, []);
return (
<iframe
title="Permit Element user-management"
src="<https://embed.permit.io/user-management?envId=4e9eb067dd114f51950886a823c76c4b&darkMode=false>"
width="100%"
height="600"
style={{ border: 'none' }}
/>
);
}Yorrick Elzinga
09/24/2025, 9:55 PMYorrick Elzinga
09/24/2025, 9:55 PMYorrick Elzinga
09/25/2025, 6:51 PMpermit support automation2
09/25/2025, 6:51 PMYorrick Elzinga
09/25/2025, 7:11 PMThomas
09/25/2025, 7:35 PMYorrick Elzinga
09/25/2025, 7:40 PM