Spleen
Spleen
Explore posts from servers
KKinde
Created by Spleen on 7/14/2024 in #💻┃support
How can I get the users JWT token after logging when using the Nuxt module?
Thanks! That worked for me. In case anyone else has a similar issue I implemented it by adding this to my app.vue:
const token = useState("token");
await callOnce(async () => {
const { getToken } = useKindeClient();
token.value = await getToken();
});
const token = useState("token");
await callOnce(async () => {
const { getToken } = useKindeClient();
token.value = await getToken();
});
This makes sure the token is also provided to the client for subsequent API calls. You can then use it in your API requests like so:
useFetch(path, {
onRequest: async ({ options }) => {
const token = useState("token");
options.headers = {
Authorization: `Bearer ${token.value}`,
};
},
});
useFetch(path, {
onRequest: async ({ options }) => {
const token = useState("token");
options.headers = {
Authorization: `Bearer ${token.value}`,
};
},
});
4 replies