How do i get the current logged in user in nextjs, I know there
payload.login, is there something like
payload.currentUserHello!
For REST API see the
/meendpoint:
https://payloadcms.com/docs/rest-api/overview#auth-operationsFor Local API you can use
payload.auth({ headers }):
https://payloadcms.com/docs/local-api/overview#authHi
@654031862146007055, thank you so much, i come up with this and now it works:
import config from '@payload-config';
import { headers as getHeaders } from 'next/headers';
import { getPayload } from 'payload';
export const getCurrentUser = async () => {
const payload = await getPayload({ config });
const headers = await getHeaders();
const { user } = await payload.auth({ headers });
return user;
};Star
Discord
online
Get dedicated engineering support directly from the Payload team.