nuxt-community / auth-module

Zero-boilerplate authentication support for Nuxt 2
https://auth.nuxtjs.org
MIT License
1.93k stars 925 forks source link

How to append id on the user endpoint #1732

Open kennedyngigi4 opened 2 years ago

kennedyngigi4 commented 2 years ago

user: { property: 'email', // autoFetch: true }, clientId: '', endpoints: { login: { url: 'login', method: 'post' }, logout: { url: 'logout', method: 'post' }, user: { url: 'user/'+<clientId here>, method: 'get' } } This is part of my auth in nuxt.config.js How should I embed the clientId at the user endpoint? I am getting an error undefined

I have initialised it during login using => this.$auth.clientId = response['user_id']

sneakylenny commented 2 years ago

You should add it to your this.$auth.loginWith() method. For example:

const userId = 'YourUserId'

// As get param
this.$auth.loginWith('local', params: { userId: userId }) // Results in /api/login?userId=YourUserId
// In url
this.$auth.loginWith('local', url: `/api/login/user/${userId}`) // Results in /api/login/user/YourUserId

The second prop in loginWith() overwrites your endpoints config which takes Axios request config.