admin管理员组文章数量:1277875
I'm trying to get my firebase uid
on a nextjs client rendered page.
This is my function to get the uid
from the session cookie.
import "server-only";
export async function isUserAuthenticated(session: string | undefined = undefined) {
const _session = session ?? (await getSession());
if (!_session) return false;
try {
const decodedIdToken = await auth.verifySessionCookie(_session, true);
return decodedIdToken.uid;
} catch (error) {
console.log(error);
return false;
}
}
The problem is, for security reasons, I can only run this in server components. verifySessionCookie()
is part of the firebase-admin
lib (here).
I'd love to pass this down from my layout.tsx
but react doesn't allow passing props to {children}
and context in server components are not supported either. The only way I can think to do this is to make every single page.tsx
a server component and then pass down the uid as props from there. But this seems horrible, I'd be replicating the same code for every single URL. Is there any other solution besides this?
本文标签: javascriptHow to get uid on client rendered pages (firebasenextJS)Stack Overflow
版权声明:本文标题:javascript - How to get uid on client rendered pages? (firebase, nextjs) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741254888a2366479.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论