Martin INDIE MAKERS
03/08/2022, 4:44 PMtypescript
import type { SupabaseClientOptions } from '@supabase/supabase-js'
import { createClient } from '@supabase/supabase-js'
import type { HttpOptions } from '@capacitor-community/http'
import { Http } from '@capacitor-community/http'
export const useSupabase = () => {
const options: SupabaseClientOptions = {
autoRefreshToken: true,
persistSession: true,
detectSessionInUrl: false,
fetch: (requestInfo, requestInit) => {
if (requestInit?.method === 'POST' && requestInfo.toString().includes('/storage/')) {
return fetch(requestInfo, {
method: requestInit?.method,
headers: requestInit?.headers,
body: requestInit?.body,
})
}
return Http.request({
url: requestInfo.toString(),
method: requestInit?.method,
headers: requestInit?.headers as any || {},
data: requestInit?.body,
})
.then((data) => {
const resp = new Response(JSON.stringify(data.data), {
status: data.status,
headers: data.headers,
})
return resp
})
}
}
return createClient(supabaseUrl, supabaseAnonKey, options)
}
cbert
03/08/2022, 5:28 PMmessage: 'null value in column "id" of relation "goals_blocked" violates not-null constraint',
after running an upsert as follows:
const { data: goalBlocked, error } = await supabase.from('goals_blocked').upsert({
id: body.id,
user_id: body.userId || locals.user.id,
workspace_id: body.workspaceId,
goal_id: body.goalId,
is_blocked: body.isBlocked,
updated_at: new Date().toISOString()
})
See screenshot for table in supabase. I can see why the error happens, if there is no entry yet, the id passed is null
, but isn't that the idea of upsert? If there is no id it creates an entry if not it updates it? Thanks for any help!
EDIT: current workaround is to generate uuid in js as fallback:
id: body.id || uuidv4(),
elliott
03/08/2022, 5:56 PMelliott
03/08/2022, 5:56 PMDanMossa
03/08/2022, 8:17 PMPukima
03/09/2022, 12:19 PMPukima
03/09/2022, 12:19 PMgaryaustin
03/09/2022, 4:09 PMPukima
03/09/2022, 6:04 PMjs
const { data: newData } = await supabase
.from('messages')
.insert([{ message_id: `${data.length + 1}`, title: `${title}`, message: `${message}`, created_at: `${new Date()}` }]);
And this is my table config:Scott P
03/09/2022, 6:09 PMconst {data. error} = /* supabase call */
will tell you what the problem is.Pukima
03/09/2022, 6:46 PMkresimirgalic
03/10/2022, 6:56 PMOlyno
03/11/2022, 1:52 PMTMShader
03/11/2022, 9:55 PMgaryaustin
03/11/2022, 11:03 PMasleepingpanda
03/12/2022, 8:47 PMsupabaseClient.auth.setAuth(access_token)
, but I get null
for the return value of user
every time with no error
being thrown..?garyaustin
03/12/2022, 9:12 PMupwell
03/13/2022, 4:02 PMupwell
03/13/2022, 4:03 PMgaryaustin
03/13/2022, 4:32 PMupwell
03/13/2022, 4:33 PMupwell
03/13/2022, 4:33 PMgirishso
03/14/2022, 2:21 AMfetch
... https://discord.com/channels/839993398554656828/843999948717555735/952444999549730846DanMossa
03/14/2022, 3:55 AMLukas
03/14/2022, 4:23 AMFainaru
03/14/2022, 5:49 AMpheralb
03/14/2022, 2:21 PMts
const handleLogin = async () => {
const { error } = await supabase.auth.signIn({provider: "github"});
if (error) {
alert(JSON.stringify(error));
}
};
and I get the user. But when I access a path protected with getServerSideProps: ts
export const getServerSideProps: GetServerSideProps = async ({ req }) => {
const { user } = await supabase.auth.api.getUserByCookie(req);
if (!user) {
return { props: {}, redirect: { destination: "/" } };
}
return { props: { user } };
};
the user is always null. My "pages/api/auth.ts": ts
export default function handler(req: NextApiRequest, res: NextApiResponse) {
supabase.auth.api.setAuthCookie(req, res)
}
. Does anyone know how to get user once logged into the protected page? 🤔silentworks
03/14/2022, 2:41 PMswiss
03/14/2022, 10:34 PMBallisticSwami
03/15/2022, 10:01 AM