Authorize frontend users without redirecting to Universal Login

Hello,

I’m trying to authorize users to another application but I keep getting redirected to the Universal Login page even if I’m already logged in and I have the token. I’m running the code below after I log in the user and save the token in a session cookie

const state = "some state here"
const webAuth = new WebAuth({
      domain: "DOMAIN HERE",
      clientID: "CLIENT ID HERE",
      redirectUri: "REDIRECT URI",
      responseType: 'code',
      scope: 'openid',
      audience: "AUDIENCE",
    });
    webAuth.authorize({connection: 'metadata', state });

Works fine if I change the connection to a provider like facebook but not if the connection is set to a database.

Is there a way to authorize users on the frontend or backend by calling an endpoint with the existing token?