question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use API token in Nuxt3

See original GitHub issue

Hi,

I’m not using user authentication on my app, but I’m wanting to protect my API with the API Token.

How can I put the API token into the header request?

await create<Strapi4Response<Subscriber>>("subscribers", {
      email: data.email,
    });

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
benjamincanaccommented, Mar 1, 2022

Hi @IzakJackson,

An easy solution for now could be to use the client directly, you can check out the documentation here https://strapi.nuxtjs.org/usage#usestrapiclient.

Here is an example:

const client = useStrapiClient()

await client<Strapi4Response<Subscriber>>('/subscribers', {
  method: 'POST',
  body: {
    data: {
      email: data.email
    }
  },
  headers: {
     ...
  }
})

For informations, the create method is juste a wrapper around the client, you can check out the code here https://github.com/nuxt-community/strapi-module/blob/dev/src/runtime/composables/useStrapi4.ts#L43

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nuxt 3 JWT authentication using $fetch and Pinia
get JWT token and user info from API (edit: done!) and store both (to keep user logged even if a page is refresh);...
Read more >
Where store user Token in my Nuxt 3 app? #10402 - GitHub
Hi, I'm using Nuxt 3 with a fullstack approach, I'm using Pinia for the store, and Prisma as ORM to interact with my...
Read more >
Auth in Nuxt 3 the EASY WAY - YouTube
Check out Storyblok (especially their Nuxt 3 module): ... ( definitely use this, I went fast in the video lol) Supabase Authentication : ......
Read more >
How To Add Auth To A Nuxt App in Minutes with Amplify!
Nuxt 3 + Authentication : How To Add Auth To A Nuxt App in Minutes with ... and how you can use this...
Read more >
How to Implement auth0 Authentication in Nuxt3
So let's start with the Nuxt3 project. npx nuxi init nuxt-app. I am using a JavaScript library from auth0 “@auth0/auth0-spa-js”. npm i @auth0/auth0-spa-js....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found