KrisGunnars
11/15/2021, 1:54 AMjonny
11/15/2021, 3:59 AMprofiles
which can contain whatever user metadata you like.
could also add a enum type for the user_status column
sql
CREATE TYPE user_status AS ENUM ('trialing', 'active', 'cancelled');
CREATE TABLE profiles (
id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
-- foreign key that uses auth.users, so the UUID here has to match one of your users
user_id uuid REFERENCES auth.users NOT NULL,
inserted_at timestamp with time zone DEFAULT timezone('utc'::text, now()) NOT NULL,
updated_at timestamp with time zone DEFAULT timezone('utc'::text, now()) NOT NULL,
-- column for user_status, using the enum type made above
user_status user_status DEFAULT 'active'
)
KrisGunnars
11/15/2021, 4:00 AMKrisGunnars
11/15/2021, 4:00 AMKrisGunnars
11/15/2021, 4:01 AMKrisGunnars
11/15/2021, 4:02 AMjonny
11/15/2021, 4:06 AMauth
schema in your api, but I think that schema is protected. Then you could of queried a foreign table at the same time as auth.users
jonny
11/15/2021, 4:07 AMKrisGunnars
11/15/2021, 4:08 AMraimundo (kalendme.com)
12/16/2021, 1:45 PMraimundo (kalendme.com)
12/16/2021, 2:11 PMraimundo (kalendme.com)
12/16/2021, 2:11 PMimport { NextApiRequest, NextApiResponse } from "next"
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try {
if (req.method === "PATCH") {
const { userId } = req.query
const { appMetadata } = req.body
if (!appMetadata) {
res.status(400).json({ error: "Missing appMetadata" })
return
}
const url = `${process.env.NEXT_PUBLIC_SUPABASE_URL}/auth/v1/admin/users/${userId}`
const options = {
method: 'PUT',
body: JSON.stringify({ app_metadata: appMetadata }),
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.SUPABASE_SERVICE_KEY}`,
'apikey': process.env.SUPABASE_SERVICE_KEY,
}
}
const result = await fetch(url, options)
.then(res => res.json())
res.status(200).json({ user: result })
} else {
res.status(405).json({ error: 'Method not allowed' })
}
} catch (error) {
res.status(500).json({ error: error.message || JSON.stringify(error) })
}
}
raimundo (kalendme.com)
12/16/2021, 2:12 PMraimundo (kalendme.com)
12/16/2021, 2:13 PMraimundo (kalendme.com)
12/16/2021, 2:13 PMjonny
12/16/2021, 9:34 PMjonny
12/16/2021, 9:36 PM