#Hello someone know how to get current

1 messages · Page 1 of 1 (latest)

wary quiver
proven peakBOT
#

Hi @wary quiver. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

wary quiver
#

@proven peak

proven peakBOT
#

Sorry @wary quiver, I seem to be having a bit of trouble. Don't worry though, I've pinged my supprt and they will try to fix me up! :technologist:

Perhaps try again in 15mins?

#

Let me check the knowledge base for you. One moment! :books:

#

Sorry @wary quiver, I seem to be having a bit of trouble. Don't worry though, I've pinged my supprt and they will try to fix me up! :technologist:

Perhaps try again in 15mins?

wary quiver
#

server side or api route?

#

it should be on the req. object.

scenic narwhal
#

server component sorry

wary quiver
#

const { req, query, res, asPath, pathname } = context;

scenic narwhal
#

I have a sidebar and the only reason i have 'use client' is a usePath on my items to know if it's active item

wary quiver
#

ok hang on.

scenic narwhal
#

context is available in server components ?

wary quiver
#

import { useRouter, usePathname, useSearchParams } from 'next/navigation';

#

no you have to use the new router from nextNavigation!

scenic narwhal
#

usePathname is not available in server component :/

#

so i have to keep my use client ?

young tundra
#

as far as i know you cant really access the request object in the nextjs13, the only things you can extract are the headers and the cookies of a request.

scenic narwhal
#

ohh okay..

young tundra
#

so the only workaround which people use is using the middleware of nextjs13 and setting the url on the header and returning it

#

on the server component you can then fetch the url which was set in the header from the middleware.

#

idk why it isnt implemented yet tbh

scenic narwhal
#

i already use a middleware for translations, i never work with multple middlewares, it's possible ?

wary quiver
#

yeah I just checked, middleware is how I did it as well...

#

its a bit of a hackery tbh...

scenic narwhal
#

i see, thank you for your investigations

scenic narwhal
young tundra
#

you can do that in one file, you can also do some operations only on specific paths by checking the pathname of the request if you mean that.

scenic narwhal
#

this middleware is for my translations, but if i have to transform request i want to separate the logic in another middleware file

young tundra
scenic narwhal
#

okay i see

young tundra
#

i mean you can split your utility functions into own modules to make it cleaner

wary quiver
scenic narwhal
#

it's not mine middleware..

import createIntlMiddleware from 'next-intl/middleware'

import i18nConfig from '@/settings/i18n'

export default createIntlMiddleware({
  ...i18nConfig,
})

it's the i18n middleware provided by the library quoted in the nextjs documentation

#

i cannot custom this

young tundra
#

never worked with it sorry

#

ive only used the custom next-auth middleware once but there is a option to extend their middleware