Querying DB returning same row for two different userIds

Hi everyone 👋 , I am running into an issue where I have two different users logged in (one on Chrome and one on Safari) to test multiple users logging in at once. One user has submitted a ballot and the other has not. However, with the one that has not voted, hasVoterVoted is returning true AND getUsersVote is returning the vote of the other user. I logged out user.userId and they are different in each call... So why would drizzle/supabase be returning the exact same information for two different userId? My guess is due to the eq(model.userId, user.userId) && eq(model.year, year) && eq(model.week, week) because if I remove the check for year and week in the hasVoterVoted, it returns false for the user who has not voted.
1 Reply
jsingleton37
jsingleton37OP•6mo ago
Hmm I think I need to do
export async function hasVoterVoted({ year, week }: GetUsersVote) {
const user = auth()

if (!user.userId) throw new Error('Unauthorized')

const vote = await db.query.ballots.findFirst({
where: (model, { eq, and }) =>
and(eq(model.userId, user.userId), eq(model.year, year), eq(model.week, week)),
})

return !!vote
}
export async function hasVoterVoted({ year, week }: GetUsersVote) {
const user = auth()

if (!user.userId) throw new Error('Unauthorized')

const vote = await db.query.ballots.findFirst({
where: (model, { eq, and }) =>
and(eq(model.userId, user.userId), eq(model.year, year), eq(model.week, week)),
})

return !!vote
}
Want results from more Discord servers?
Add your server