File tree Expand file tree Collapse file tree 3 files changed +21
-8
lines changed
Expand file tree Collapse file tree 3 files changed +21
-8
lines changed Original file line number Diff line number Diff line change @@ -130,10 +130,23 @@ export async function getUserByEmail(email: string){
130130 return prisma . user . findUnique ( { where : { email} } ) ;
131131}
132132
133+ export async function getAuthUserIdOrNull ( ) {
134+ const session = await auth ( ) ;
135+ const userId = session ?. user ?. id ;
136+
137+ if ( ! userId ) return null ;
138+
139+ const existingUser = await prisma . user . findUnique ( {
140+ where : { id : userId } ,
141+ select : { id : true }
142+ } ) ;
143+
144+ return existingUser ?. id ?? null ;
145+ }
146+
133147
134148export async function getAuthUserId ( ) {
135- const session = await auth ( ) ;
136- const userId = session ?. user ?. id ;
149+ const userId = await getAuthUserIdOrNull ( ) ;
137150
138151 if ( ! userId ) throw new Error ( "Unauthorized" ) ;
139152 return userId ;
Original file line number Diff line number Diff line change 44 fetchLikeMembers ,
55} from "../actions/likeActions" ;
66import ListsTab from "./ListsTab" ;
7- import { auth } from "@/auth " ;
7+ import { getAuthUserIdOrNull } from "../actions/authActions " ;
88import { redirect } from "next/navigation" ;
99
1010export const dynamic = "force-dynamic" ;
@@ -14,9 +14,9 @@ export default async function ListsPage({
1414} : {
1515 searchParams : Promise < { type ?: string } > ;
1616} ) {
17- const session = await auth ( ) ;
17+ const userId = await getAuthUserIdOrNull ( ) ;
1818
19- if ( ! session ?. user ?. id ) {
19+ if ( ! userId ) {
2020 redirect ( "/login" ) ;
2121 }
2222
Original file line number Diff line number Diff line change @@ -6,15 +6,15 @@ import PaginationComponent from '@/components/PaginationComponent';
66import Filters from '@/components/navbar/Filters' ;
77import { GetMemberParams } from '@/types' ;
88import EmptyState from '@/components/EmptyState' ;
9- import { auth } from '@/auth ' ;
9+ import { getAuthUserIdOrNull } from '../actions/authActions ' ;
1010import { redirect } from 'next/navigation' ;
1111
1212export default async function MembersPage ( { searchParams, } :{
1313 searchParams : Promise < GetMemberParams > ;
1414} ) {
15- const session = await auth ( ) ;
15+ const userId = await getAuthUserIdOrNull ( ) ;
1616
17- if ( ! session ?. user ?. id ) {
17+ if ( ! userId ) {
1818 redirect ( '/login' ) ;
1919 }
2020
You can’t perform that action at this time.
0 commit comments