next session is lost on refresh

Hi people, I have a problem that my session is lost on page refresh. I have getInitalProps in my _app.tsx and I can't manage to get session from there and pass it in SessionProvider I have tried getSession and ustable_getServerSession but both don't work. Is there any workaround, for this?
7 Replies
barry
barry3y ago
No clue what you done since you don’t share code, my guess is use the useSession hook?
julius
julius3y ago
you mean lost as if you need to sign in again or you get loading state for a bit?
Bozic0909
Bozic0909OP3y ago
I will share a code example and errors i get in 10-15 mins, i want server session
julius
julius3y ago
are you using trpc? with getInitialProps it should look something like t his
const MyApp: AppType<{ session: Session | null }> = ({
Component,
pageProps,
}) => {
return (
<SessionProvider session={pageProps.session}>
<Component {...pageProps} />
</SessionProvider>
);
};

MyApp.getInitialProps = async ({ ctx }) => {
return {
session: await getSession(ctx),
};
};

export default trpc.withTRPC(MyApp);
const MyApp: AppType<{ session: Session | null }> = ({
Component,
pageProps,
}) => {
return (
<SessionProvider session={pageProps.session}>
<Component {...pageProps} />
</SessionProvider>
);
};

MyApp.getInitialProps = async ({ ctx }) => {
return {
session: await getSession(ctx),
};
};

export default trpc.withTRPC(MyApp);
Bozic0909
Bozic0909OP3y ago
I have still "logged in" state in my navbar, but i get unauthorized errors whenever i need to pass jwt to request No i dont use trpc, its next.js next auth and axios
julius
julius3y ago
ok so omit the last line and just export the app unwrapped
Bozic0909
Bozic0909OP3y ago
Ok, thanks, will try sry for late update, yeah that solved problem thank you 😄
Want results from more Discord servers?
Add your server