eoin
04/19/2022, 8:40 PMuser.uid is in a players array can access a /game/game.uuid route. It's working, but the "blocked" route is firing a 304 request to /api/game/null (guessing once RLS is hit) and then throwing code:22P02, message; invalid input syntax for type uuid: \\\"null\\\". It then tries to render the component with no data and fails.
Ideal state is that I can handle this more gracefully, add that the user.uid doesn't have access to this particular route to state and render an input field for them to enter a code which—if correct—would add their user.uid to the original players array, therefore meeting the criteria of the policy and providing access.
Does anyone know how to better handle this redirect to /api/game/null and use it to control state rather than crash out?Needle
04/19/2022, 8:40 PM/title command!
We have solved your problem?
Click the button below to archive it.eoin
04/19/2022, 9:01 PMsilentworks
04/20/2022, 2:48 AMNeedle
04/20/2022, 2:48 AMeoin
04/20/2022, 11:07 AMcode:22P02 response, but feel like that may not be correct? And if it is correct, are there guidelines for more gracefully handling it?eoin
04/22/2022, 12:53 PM/api/game/null route in my fetcher.ts file, but that seems like a super hacky way and I can't actually get it into state on a server route like that (afaik). Thank you! 🙏silentworks
04/22/2022, 1:09 PMeoin
04/22/2022, 1:14 PM/game/gameId and if the current user's ID isn't in the players array, then RLS kicks in. So handling the response to that is where I'm currently stuck.eoin
04/22/2022, 1:15 PMif (error) section?
js
import type { NextApiRequest, NextApiResponse } from 'next'
import {
withAuthRequired,
supabaseServerClient,
} from '@supabase/supabase-auth-helpers/nextjs'
import supabase from '@/utils/supabase'
export default withAuthRequired(async function ProtectedRoute(
req: NextApiRequest,
res: NextApiResponse
) {
const { user } = await supabase.auth.api.getUserByCookie(req)
const { data: test_games, error } = await supabaseServerClient({ req, res })
.from('test_games')
.select('*')
.eq('uuid', req.query.gameId)
if (error) {
res.send({ message: JSON.stringify(error) })
return
}
res.json(test_games)
})eoin
04/22/2022, 1:15 PMres.send then?eoin
04/22/2022, 1:19 PM[...game].tsx file where I fetch the API route above that depends on the Supabase SELECT for it's response:
js
import type { NextPage } from 'next'
import Link from 'next/link'
import { useRouter } from 'next/router'
import useSWR from 'swr'
import fetcher from '@/utils/fetcher'
const Game: NextPage = () => {
const router = useRouter()
const route = router.query?.game
const gameId = route ? route[0] : null
const { data: gameData, error } = useSWR(`/api/game/${gameId}`, fetcher)
// TODO: Handle error here: Still trying to render HTML below
if (error) return <div>{error}</div>
if (!gameData) return <div>loading...</div>
return (
<>
<Link href="/">Home</Link>
<ul>
<li>
<b>Title:</b> {gameData[0].title}
</li>
<li>
<b>ID:</b> {gameData[0].uuid}
</li>
<li>
<b>Share code:</b>
{gameData[0].share_code}
</li>
<li>
<b>Players:</b> {gameData[0].players}
</li>
</ul>
</>
)
}
export default Game
The error is not getting hit here at all, and instead it's trying to render gameData[0].title with the /api/game/null redirect I mentioned, therefore crashing the app.
Not sure if this helps clarify what I'm trying to do.silentworks
04/22/2022, 1:22 PMeoin
04/22/2022, 1:29 PMsilentworks
04/22/2022, 7:34 PMeoin
04/24/2022, 3:15 PMsilentworks
04/24/2022, 7:56 PM