#How to authenticate SDK with Token

2 messages · Page 1 of 1 (latest)

violet novaBOT
#

Thanks for posting! This is a community powered server, so you may or may not get an answer based on available help and expertise. To increase your chances of somebody being able to help you, please help us help you making sure you:

  • Adding an explanation of exactly what you're trying to achieve.
  • Adding any and all related code or previous attempts.
  • Describing the exact issue or error you are facing.
  • Posting any screenshots if applicable.
  • Reading through https://stackoverflow.com/help/how-to-ask.

When you're done with this thread, please close it. Thanks! ✨

(If you have a support agreement and need help, please contact the core team via email.)

brisk coral
#

Try using setToken. This worked for me for a service account I am using with a static token set.

Here is a snippet of my ConnectDirectus function:

async function ConnectDirectus({ url, email, pw, token }) {
  console.log('>> Directus: Creating client');
  const client = createDirectus(url)
    .with(rest())
    .with(graphql())
    .with(authentication('json'));

  console.log(`Directus: Connecting as ${email}`);
  try {
    // await client.login(email, pw);
    await client.setToken(token) // login using static token
    return client;
  } catch (e) {
    console.log('>> Error: ', e);
    return null;
  }
}