Nisthar
Nisthar
Explore posts from servers
NNuxt
Created by Nisthar on 10/31/2024 in #❓・help
How to pass data from plugins to server api endpoint in nuxt 3?
when i send requests using fetch from the client, this plugin won't get executed Right? @manniL
20 replies
NNuxt
Created by Nisthar on 10/31/2024 in #❓・help
How to pass data from plugins to server api endpoint in nuxt 3?
I will post the plugin code here:
import { defineNuxtPlugin, useRuntimeConfig } from '#app'


export default defineNuxtPlugin(async (nuxtApp) => {

const config = useRuntimeConfig();
const { fetchUser } = useAuth();
const { token, checkAutoRefresh } = useToken();
const user = useUser();

async function checkIfUserExists() {
if (config.public.autoFetch) {
if (!user.value && token.value) {
await fetchUser();
}
}
}

// do the checks server-side, instead of using hook 'app:created',
// as this hook is not called on SSR=true (static generation)
await checkAutoRefresh();
await checkIfUserExists();

nuxtApp.hook('page:start', async () => {
if (import.meta.client) {
await checkAutoRefresh();
await checkIfUserExists();
}
})
})
import { defineNuxtPlugin, useRuntimeConfig } from '#app'


export default defineNuxtPlugin(async (nuxtApp) => {

const config = useRuntimeConfig();
const { fetchUser } = useAuth();
const { token, checkAutoRefresh } = useToken();
const user = useUser();

async function checkIfUserExists() {
if (config.public.autoFetch) {
if (!user.value && token.value) {
await fetchUser();
}
}
}

// do the checks server-side, instead of using hook 'app:created',
// as this hook is not called on SSR=true (static generation)
await checkAutoRefresh();
await checkIfUserExists();

nuxtApp.hook('page:start', async () => {
if (import.meta.client) {
await checkAutoRefresh();
await checkIfUserExists();
}
})
})
user is a state like this
export const useUser = (): Ref<User> =>
useState<User>('current.user')
export const useUser = (): Ref<User> =>
useState<User>('current.user')
20 replies
NNuxt
Created by Nisthar on 10/31/2024 in #❓・help
How to pass data from plugins to server api endpoint in nuxt 3?
But i am not getting the user data using the cookies on server.
20 replies
NNuxt
Created by Nisthar on 10/31/2024 in #❓・help
How to pass data from plugins to server api endpoint in nuxt 3?
Yeah i am already sending the cookies from the client.
20 replies
NNuxt
Created by Nisthar on 10/31/2024 in #❓・help
How to pass data from plugins to server api endpoint in nuxt 3?
Only need to get the user data on the server and middleware is not working for it
20 replies
NNuxt
Created by Nisthar on 10/31/2024 in #❓・help
How to pass data from plugins to server api endpoint in nuxt 3?
Iam already sending the tokens via cookies from the client
20 replies
NNuxt
Created by Nisthar on 10/31/2024 in #❓・help
How to pass data from plugins to server api endpoint in nuxt 3?
You mean from the client using a custom fetch ?
20 replies
NNuxt
Created by Nisthar on 10/31/2024 in #❓・help
How to pass data from plugins to server api endpoint in nuxt 3?
any ideas?
20 replies
NNuxt
Created by Nisthar on 10/31/2024 in #❓・help
How to pass data from plugins to server api endpoint in nuxt 3?
does this work for each and every users?
20 replies
NNuxt
Created by Nisthar on 10/31/2024 in #❓・help
How to pass data from plugins to server api endpoint in nuxt 3?
// In your plugin
export default defineNuxtPlugin((nuxtApp) => {
// Your token refresh logic here
// ...

// Expose the user data through useNuxtApp
return {
provide: {
userData: /* your user data here */
}
}
})

// In your server API endpoint
export default defineEventHandler(async (event) => {
const { $userData } = useNuxtApp()
// Use $userData in your API logic
})
// In your plugin
export default defineNuxtPlugin((nuxtApp) => {
// Your token refresh logic here
// ...

// Expose the user data through useNuxtApp
return {
provide: {
userData: /* your user data here */
}
}
})

// In your server API endpoint
export default defineEventHandler(async (event) => {
const { $userData } = useNuxtApp()
// Use $userData in your API logic
})
Isn't this for providing the data globally throughout the whole app?
20 replies
NNuxt
Created by Nisthar on 9/15/2024 in #❓・help
why isn't input's value not updating when using useState value in it?
Yes i was expecting the input changes when the state changes
18 replies
NNuxt
Created by Nisthar on 9/15/2024 in #❓・help
why isn't input's value not updating when using useState value in it?
It might be why its not working
18 replies
NNuxt
Created by Nisthar on 9/15/2024 in #❓・help
why isn't input's value not updating when using useState value in it?
No its a shadcn-vue input component.
18 replies
NNuxt
Created by Nisthar on 9/15/2024 in #❓・help
why isn't input's value not updating when using useState value in it?
using v-model works, but i don't know why :value doesn't work for this
18 replies
NNuxt
Created by Nisthar on 9/15/2024 in #❓・help
why isn't input's value not updating when using useState value in it?
but doesn't the input need to update when the value changes even if it is one way binding?
18 replies
NNuxt
Created by Nisthar on 9/15/2024 in #❓・help
why isn't input's value not updating when using useState value in it?
aren't they both the same?
18 replies
NNuxt
Created by Nisthar on 9/15/2024 in #❓・help
why isn't input's value not updating when using useState value in it?
how is this different from the code?
18 replies
NNuxt
Created by Nisthar on 9/8/2024 in #❓・help
Uncaught SyntaxError: The requested module '/_nuxt/middleware/auth.global.ts' when restarting nuxt
anyone know what could be causing this error?
2 replies
NNuxt
Created by Nisthar on 9/3/2024 in #❓・help
How to use layouts (using named slots)?
also this is incorrect.
118 replies
NNuxt
Created by Nisthar on 9/3/2024 in #❓・help
How to use layouts (using named slots)?
The use case is not repeating the same layout code for all the sub pages and being able to change it from a single place.
118 replies