stibbs
07/29/2021, 5:23 AMreq.headers.token
does contain a valid tokenuser
07/29/2021, 5:25 AMgetUserByCookie
is the incorrect method then? Try the getUser
method insteadstibbs
07/29/2021, 5:26 AM{"user":null,"data":null,"error":{}}
stibbs
07/29/2021, 5:26 AMstibbs
07/29/2021, 5:27 AMArgument of type 'string | string[] | undefined' is not assignable to parameter of type 'string'.
Type 'undefined' is not assignable to type 'string'.ts(2345)
user
07/29/2021, 5:30 AMgetUser
.user
07/29/2021, 5:31 AMstibbs
07/29/2021, 5:38 AMstibbs
07/29/2021, 5:39 AMstibbs
07/29/2021, 5:39 AMconst { data, error } = await supabase
.from('settings')
.select('*')
.eq('user_id', user.id);
stibbs
07/29/2021, 5:42 AMfrubalu
07/29/2021, 5:52 AMstibbs
07/29/2021, 6:16 AMsilentworks
07/29/2021, 6:17 AMstibbs
07/29/2021, 6:23 AMstibbs
07/29/2021, 6:24 AMsilentworks
07/29/2021, 6:30 AMsettings
table for that user?stibbs
07/29/2021, 7:08 AMstibbs
07/29/2021, 7:10 AM2e97bd50-8f02-4e70-a91f-adf9d15fe53b
silentworks
07/29/2021, 7:14 AMstibbs
07/29/2021, 7:15 AMALTER TABLE settings ENABLE ROW LEVEL SECURITY;
CREATE POLICY "Individuals can create their own settings." ON public.settings FOR
INSERT
WITH CHECK ((auth.uid() = user_id));
CREATE POLICY "Individuals can update their own settings." ON public.settings FOR
UPDATE
USING ((auth.uid() = user_id));
CREATE POLICY "Individuals can read their own settings." ON public.settings FOR
SELECT
USING ((auth.uid() = user_id));
silentworks
07/29/2021, 7:17 AM.eq
from your supabase js code and see if it makes a difference, because in your RLS it should only return the one belonging to that user anywaystibbs
07/29/2021, 7:18 AMsilentworks
07/29/2021, 7:20 AMerror
variablestibbs
07/29/2021, 7:22 AMconst { user } = await supabase.auth.api.getUser(req.headers.token);
console.log(`Settings API user: ${user?.id}`);
const { settings, error } = await getSettings();
console.log(`Settings API data: ${settings}`);
console.log(`Settings API error: ${error}`);
The logged output
Settings API user: 2e97bd50-8f02-4e70-a91f-adf9d15fe53b
Settings API data:
Settings API error: null
getSettings()
export const getSettings = async () => {
const { data: settings, error } = await supabase.from('settings').select('*');
return { settings, error };
};
Mark ES
07/29/2021, 7:24 AMhieu
07/29/2021, 7:33 AMhieu
07/29/2021, 7:35 AMMark ES
07/29/2021, 7:35 AMstibbs
07/29/2021, 7:37 AM