Reputation: 1
I need to get the clerk id to check with the backend but clerk uses a hook which doesnt work in this type of function
export const getServerSideProps = async ({ req }) => {
const { isLoaded, isSignedIn, user } = useUser();
const userman = user.id;
const posts = await prisma.kalender.findMany({
where:{accountid: userman}
})
await prisma.$disconnect();
return { props: { posts: JSON.parse(JSON.stringify(posts)) } }
}
This is how i would like it to work. Is there a way to get the user.id as a string? Thanks!
Upvotes: 0
Views: 5277
Reputation: 2732
You can use type assertion.
1. Type assertion on UseUser
.
First create a new type (above export const
):
interface UseUserT {
isLoaded: boolean;
isSignedIn: boolean;
user: { id: string };
}
Then assign this type to useUser
:
const { isLoaded, isSignedIn, user } = useUser() as UseUserT;
2. Type assertion on user.id
.
const userman = user.id as string;
Upvotes: 0
Reputation: 1
You can cast user.id
to string
.
user.id.toString()
or String(user.id)
, both will act the same if user.id
is defined.
Ref:
Upvotes: 0