How to get token from sessionstorage to custom nodes

Hi N8N Team,
After integrating n8n in our product , we need to remove the credentials dropdown from custom node and we are trying to pass authentication token from frontend session storage to n8n custom node , for that we are declaring the below code in our custom node

declare global {
var jwtToken: any ;
}
let jwtToken = sessionStorage.getItem('token')

but we are getting error like “”“Error: There was an error: sessionStorage is not defined”“”
can you give any example of how to solve this issue

Hi @praveen, I am not sure this is possible tbh. Perhaps @marcus know whether this can be achieved?

Hi @praveen,
a browser’s sessionStorage cannot be accessed from your custom node, because your node executions are not running in the browser but inside the nodejs backend of n8n. Generally everything happening in the browser frontend is decoupled from nodes being executed in the backend.

3 Likes

Hi @marcus ,
can you suggest any other approach of how to take the token inside nodes, by avoiding the credentials dropdown in the custom nodes.

Hey @praveen,

You could use Env options or hard code the values in the nodes, If it needed to be more dynamic maybe your custom node could query a database to get the values it needs.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.