Skip to content

Use sanctumClient in a server route #373

Answered by manchenkoff
ahoiroman asked this question in Q&A
Discussion options

You must be logged in to vote

I'm back with some findings 😄 so, if you want to use a server route and still pass everything from the client side, you can use this forwarding approach in Nuxt - Forwarding Context Headers.

Unfortunately, the Nuxt instance is not available in the server routes since it is handled by Nitro, so there is no easy way to use module composables.

I've tested that on a signed secure route covered by sanctum auth and here is what I have in my server route:

// app/server/api/link/[id].vue
export default defineEventHandler(
  async (event) => {
    const signature = getRouterParam(event, 'id') // retrieve signature from URL
    const endpoint = 'http://localhost/api/link/1' // Laravel API endpoint,…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@ahoiroman
Comment options

ahoiroman May 12, 2025
Author Sponsor

@manchenkoff
Comment options

@manchenkoff
Comment options

Answer selected by manchenkoff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants