the request isn’'t authenticated, then the currentUser won’t exist on the context. In that case where you are trying to get authenticated info in a not authenticated request, you can:
As for the type of the CurrentUser that can depend on your implementation. For example, in Supabase the auth lib ships as:
/**
* Represents the user attributes returned by the decoding the
* Authentication provider's JWT together with an optional list of roles.
*/
type RedwoodUser = Record<string, unknown> & { roles?: string[] }
/**
* ........
* @returns RedwoodUser
*/
export const getCurrentUser = async (
decoded,
/* eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars */
{ token, type },
/* eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars */
{ event, context }
): Promise<RedwoodUser> => {
if (!decoded) {
return null
}
const { roles } = parseJWT({ decoded })
if (roles) {
return { ...decoded, roles }
}
return { ...decoded }
}```
So, `getCurrentUser` is typed as a `RedwoodUser`. Which for Supabase is an object of JWT claims (plus role moved to top level).
Depending our what you return from `getCurrentUser` would should be able to type it and -- I think -- have `id ` and other properties available to you.
If your user is a Prisma model then it can be that type.
Just as always if using Prisma, make sure no sensitive fields are added to that data returned as currentUser like password hash or salt.