Replies: 4 comments 2 replies
-
I will have to take a look. With the new nuxt payload plugins there might be a way to have a universal customClaims but I'm not sure yet |
Beta Was this translation helpful? Give feedback.
-
@noook did you ever get this working? its something im needing to add on my end as well. |
Beta Was this translation helpful? Give feedback.
-
I faced the same issue some time ago and made a I know this is a temporary check and wanted to have an opinion on this (does it have to be handled by Here is my composable: // `~/composables/useUser.ts`
import { getIdTokenResult, ParsedToken } from "firebase/auth";
import { CustomClaims } from "~/types/users";
export const getUserCustomClaims = async (): Promise<
(ParsedToken & CustomClaims) | null
> => {
if (process.server || import.meta.env.MODE === 'production') {
const idTokenResult = await getIdTokenResult(await getCurrentUser());
return idTokenResult.claims;
} else {
const user = useCurrentUser();
if (user.value) {
const idTokenResult = await getIdTokenResult(user.value);
return idTokenResult.claims;
} else {
return null;
}
}
}; |
Beta Was this translation helpful? Give feedback.
-
Maybe I can help with this one! For client-side, there are two ways I've generally used to handle RBAC. useCurrentUser():
getCurrentUser()
For server-side stuff like API endpoints, I use firebase-admin directly. Been way easier IMO to pass a token as a header, then verify/decode with firebase-admin SDK. If anyone's got a better way to do the server-side stuff feel free to lmk. Server-Side (API Endpoint) w/ Firebase-Admin SDK
|
Beta Was this translation helpful? Give feedback.
-
How to protect a route given the roles a user might have in their token claims ?
As of now, I already set the
role
claim and gave it an array of roles, however the claims are not available within the user returned bygetCurrentUser()
in a middleware. However, the claims are available in the decoded IdToken, but the functions to get it / read it are not available server-sideupdate:
By using
console.log
I noticed there is actually the propertycustomClaims
attached to the user. After digging into the typedefs fromgetCurrentUser
, I was using theUser
type fromfirebase/auth
on which there is no such property.I guess the real issue here is what is the real return type of
getCurrentUser
, and why is it inferred to any on a Nuxt 3 (3.2) project ?The ideal way would be to do that:
Beta Was this translation helpful? Give feedback.
All reactions