moxdisboss
03/14/2023, 6:07 PMnbert
03/14/2023, 8:14 PMnpx supabase gen types typescript ...
types.
The following:
ts
let { data } = await supabase
.from('table')
.select(`*, tool ( id, category, name )`);
returns a data object with for data.tool
the type: ts
tool: (number & {
id: unknown;
category: unknown;
name: unknown;
}) | (number & {
id: unknown;
category: unknown;
name: unknown;
}[]);
with data.tool
being either an object or an array... But returning an array shouldn't be possible since the foreign key is a unique key, so it can only be a single object. Is there a way to make supabase only select the first result, or know that it cannot be an array?tsnakejake
03/14/2023, 8:30 PMRuben
03/14/2023, 8:45 PMAlesVaupotic
03/14/2023, 9:24 PMjs
{
"error": {
"code": "23505",
"details": "Key (id)=(1) already exists.",
"hint": null,
"message": "duplicate key value violates unique constraint \"countries_pkey\""
},
"status": 409,
"statusText": "Conflict"
}
I need to parse the details
to extract the column on which the value violates constraints to translate into local language and format accordingly.
Simply adding column
and value
to error
would help a lot. Any thoughts about it? Am I missing something and could simply access those properties already?ostoto
03/14/2023, 9:52 PMdmayo2
03/14/2023, 9:56 PMDYELbrah
03/15/2023, 12:09 AMjarnold
03/15/2023, 12:15 AMejkreboot
03/15/2023, 12:32 AMDYELbrah
03/15/2023, 12:39 AMDYELbrah
03/15/2023, 1:08 AMconst {
data: transactionLineItemsData2,
error: transactionLineItemsError2,
status,
statusText,
} = await ctx.supabase
.from("customer_transaction_line_item")
.select(`id, ...product ( material )`)
.eq("customer_transaction_id", id);
I just get error:
failed to parse select parameter (id,...product(material))
Looking at article: https://supabase.com/blog/postgrest-11-prereleaseDontblink
03/15/2023, 1:45 AM// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from "next";
import { createClient } from "@supabase/supabase-js";
type Data = {
name: string;
};
const supabase = createClient(
process.env.NEXT_PUBLIC_SUPABASE_URL,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY
);
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
const authHeader = req.headers.authorization;
if (!authHeader || !authHeader.startsWith("Bearer ")) {
return res.status(401).json({ error: "Unauthorized" });
}
const token = authHeader.split(" ")[1];
const { data: user, error } = await supabase.auth.getUser(token);
if (error || !user) {
return res.status(401).json({ error: "Unauthorized" });
}
let { data: user_jobs, errorFetch } = await supabase
.from("user_jobs")
.select("*");
if (errorFetch) {
console.log(errorFetch);
return res.status(500).json({ error: "Internal server error" });
}
// Handle authenticated user
return res.status(200).json({ user_jobs });
}
Now I've verified that the user != null and I've consoled logged it out to validate that the user matches where it's being sent from. When I turn on RLS and make a policy where only authenticated can read, it returns an empty array, and when I take off RLS it returns the full array of the jobs for the user. Do I have to do something with next cookies or headers in this case?Mohamed Yasser
03/15/2023, 2:12 AMDerock
03/15/2023, 2:15 AMsupabase/postgres:15.1.0.54-rc0
Env:
POSTGRES_HOST=/var/run/postgresql
PGPORT=5432
POSTGRES_PORT=5432
PGPASSWORD=verysecurepassword
POSTGRES_PASSWORD=verysecurepassword
PGDATABASE=postgres
POSTGRES_DB=postgres
/docker-entrypoint-initdb.d/99-realtime.sql
mounted with the contents:
sql
\set pguser `echo "$POSTGRES_USER"`
create schema if not exists _realtime;
alter schema _realtime owner to :pguser;
/docker-entrypoint-initdb.d/98-webhooks.sql
mounted with the contents:
/docker-entrypoint-initdb.d/99-roles.sql
mounted with the contents:
sql
-- NOTE: change to your own passwords for production environments
\set pgpass `echo "$POSTGRES_PASSWORD"`
ALTER USER authenticator WITH PASSWORD :'pgpass';
ALTER USER pgbouncer WITH PASSWORD :'pgpass';
ALTER USER supabase_auth_admin WITH PASSWORD :'pgpass';
ALTER USER supabase_functions_admin WITH PASSWORD :'pgpass';
ALTER USER supabase_storage_admin WITH PASSWORD :'pgpass';
startup command: docker-entrypoint.sh -c config_file=/etc/postgresql/postgresql.conf -c log_min_messages=fatal
logs:
The database cluster will be initialized with this locale configuration:
provider: libc
LC_COLLATE: en_US.utf8
LC_CTYPE: C.UTF-8
LC_MESSAGES: en_US.utf8
LC_MONETARY: en_US.utf8
LC_NUMERIC: en_US.utf8
LC_TIME: en_US.utf8
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Etc/UTC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
initdb: warning: enabling "trust" authentication for local connections
syncing data to disk ... ok
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
pg_ctl -D /var/lib/postgresql/data -l logfile start
waiting for server to start.... done
server started
/usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/98-webhooks.sql
BEGIN
psql:/docker-entrypoint-initdb.d/98-webhooks.sql:3: ERROR: role "supabase_admin" does not exist
JulesCoast
03/15/2023, 2:44 AMcontentType
option blank, it defaults to text. I've tried Blob
, FormData
, and File
. None seem to work. Any ideas?
Thank you!
js
const { data, error } = await db.storage
.from("gallery")
.upload("qqqq-asdf", image, {
contentType: "FormData",
});
richardoreo
03/15/2023, 3:09 AMsupermario
03/15/2023, 3:17 AMPeanut
03/15/2023, 3:36 AMnkeating
03/15/2023, 4:38 AMVik
03/15/2023, 6:17 AMŁukaszW.
03/15/2023, 8:36 AMLimuz
03/15/2023, 9:01 AMkvnfo
03/15/2023, 9:12 AMSiddharth
03/15/2023, 9:19 AMlumen
03/15/2023, 9:42 AMlumen
03/15/2023, 9:50 AMhttp://localhost:3000/#error=unauthorized_client&error_code=401&error_description=Email+link+is+invalid+or+has+expired
And then supabase automatically redirects them back to my home page (/
).
So the user fails to log in, and they don't see any information explaining the issue. How can I "see" this error on the client, so I could show the user an appropriate message?
I can't simply do something like:
javascript
if (location.hash.includes("error")) {
showErrorMessage()
}
Because the user is immediately automatically redirected to /
.Torwent
03/15/2023, 10:06 AMrnnyrk
03/15/2023, 10:12 AMtypescript
export const RoomContext = React.createContext<RoomContextType | null>(null);
export const RoomContextWrapper = ({ children, currentUser }: RoomContextProps) => {
const router = useRouter<{ roomCode: string }>();
const { roomCode } = router.query;
const [isSubscribed, setSubscribed] = useState(false);
const { users, roomId } = useRoomSubscriber({ roomCode, userId: currentUser });
const { roomChannel, roomState, onSetRoomStatus } = useRoomStatus({
roomId: roomCode,
isPlayingUser: true,
username: currentUser,
});
useEffect(() => {
console.log('MOUNT', { roomChannel, isSubscribed });
if (roomChannel && !isSubscribed) {
roomChannel.subscribe((status: `${REALTIME_SUBSCRIBE_STATES}`) => {
if (status === REALTIME_SUBSCRIBE_STATES.SUBSCRIBED) {
setSubscribed(true);
}
});
}
}, [roomChannel, isSubscribed]);
useEffect(() => {
return () => {
console.log('UNMOUNT', { roomChannel });
if (roomChannel) {
setSubscribed(false);
roomChannel.unsubscribe();
}
};
}, [roomChannel]);
const values = {
roomState,
onSetRoomStatus,
isSubscribed,
users,
username: user?.name,
};
return <RoomContext.Provider value={values}>{children(values)}</RoomContext.Provider>;
};
kilterskjalg
03/15/2023, 11:41 AM