Get session user and add property

This commit is contained in:
Brad Traversy
2024-07-10 14:57:23 -04:00
parent 5417ba807d
commit c8d47bd4d4
6 changed files with 527 additions and 37 deletions
+20
View File
@@ -0,0 +1,20 @@
import { getServerSession } from 'next-auth/next';
import { authOptions } from '@/utils/authOptions';
export const getSessionUser = async () => {
try {
const session = await getServerSession(authOptions);
if (!session || !session.user) {
return null;
}
return {
user: session.user,
userId: session.user.id,
};
} catch (error) {
console.error(error);
return null;
}
};