mx
05/24/2023, 9:14 PMиuғe
05/24/2023, 9:28 PMhttps://cdn.discordapp.com/attachments/1111043110886187069/1111043270684971028/image.png▾
auser
05/25/2023, 1:05 AMauth.users
via auth.identities
), is it possible to get the user_id?
HelpJinni
05/25/2023, 3:14 AMCokaps016
05/25/2023, 3:29 AMhttps://cdn.discordapp.com/attachments/1111133999436419142/1111133999595794483/image.png▾
Cokaps016
05/25/2023, 3:40 AMEsore
05/25/2023, 3:52 AMJohnny008
05/25/2023, 5:12 AMexport async function signInWithGoogle() {
const { session, user, error } = await supabase.auth.signInWithOAuth({
provider: "google",
options: {
redirectTo: "https://www.website.com/dashboard",
queryParams: {
access_type: "offline",
prompt: "consent",
scopes: ["https://www.googleapis.com/auth/calendar.events"],
},
},
});
if (error) {
console.log("Error: ", error);
}
}
vikay
05/25/2023, 6:03 AMOrvar
05/25/2023, 7:52 AMLuke | NonFunGerbils
05/25/2023, 7:55 AMAditya Tripathi
05/25/2023, 8:31 AMLogaritma26
05/25/2023, 8:59 AM{
id: 'bcede112-7d3e-4c49-9ab6-5101842f2a15',
aud: 'authenticated',
role: 'authenticated',
email: 'someEmail@gmail.com',
email_confirmed_at: '2023-05-20T21:21:03.322059064Z',
phone: '',
app_metadata: {
has_active_subscription: false,
provider: 'email',
providers: [ 'email' ]
},
user_metadata: {},
identities: [
{
id: 'bcede112-7d3e-4c49-9ab6-5101842f2a15',
user_id: 'bcede112-7d3e-4c49-9ab6-5101842f2a15',
identity_data: [Object],
provider: 'email',
last_sign_in_at: '2023-05-20T21:21:03.319379632Z',
created_at: '2023-05-20T21:21:03.319427Z',
updated_at: '2023-05-20T21:21:03.319427Z'
}
],
created_at: '2023-05-20T21:21:03.317314Z',
updated_at: '2023-05-20T21:21:03.322296Z'
}
but when I try to log this user, boom there is no user. Because its never created, doesn't appear on console too.
const {data: {user}, error} = await supabase.auth.admin.createUser({
email: userEmail,
password: userPassword,
email_confirm: true,
app_metadata: {
has_active_subscription: false,
},
})
this is how I create user on server sideGeoff
05/25/2023, 10:20 AMtenant_id
field (which is an integer) to the new user's app_metadata
, and I need to use this in row-level security policy.
I can't figure out the syntax for accessing this in the policy statement. I thought it would be something like this:
SQL
BEGIN;
ALTER POLICY "Enable tenant-based access" ON "public"."test" USING (tenant_id = (auth.jwt().app_metadata -> 'tenant_id'::integer));
COMMIT;
But I get a syntax error. Any ideas? Thanks!ven
05/25/2023, 10:55 AMThomas Allmer
05/25/2023, 10:36 AMsql
CREATE POLICY "Enable select for users based on user_id" ON "public"."rlt-test"
AS PERMISSIVE FOR SELECT
TO public
USING (auth.uid() = user_id)
Data looks something like this (with user_id simplified)
| id | name | user_id |
| --- | ----------- | ------- |
| 1 | John Doe | 1 |
| 2 | Jane Doe | 1 |
| 3 | Susan Smith | 2 |
so now if I do a select via the api with the user_id 1 logged in I get
- John
- Jane
if I do a select * from test
then I get
- John
- Jane
- Susan
Can I execute an sql query that will give me the same result as the API?
e.g. maybe somehow set the values that are used within auth.uid()
an idea
BEGIN;
SET LOCAL auth.jwt = '...';
SELECT * from test;
COMMIT;
it sadly does not work as I don't know which values to set... and if it can even be set that way 😅
anyone got any ideas?<hmmhmmhm/>
05/25/2023, 11:02 AMRevathar
05/25/2023, 12:52 PMTOBII
05/25/2023, 1:15 PMArjunXD
05/25/2023, 1:44 PMhttps://cdn.discordapp.com/attachments/1111288668360020009/1111288668859150428/image.png▾
Evostance
05/25/2023, 2:01 PMFEXXXXXXXXXX
where X is an alphanumerical character.
Is there a way I can put this as an expression in the Default Value?zeedee
05/25/2023, 2:18 PMsupabase remote commit --debug
gives me error
...
2023/05/25 09:05:57 PG Send: {"Type":"StartupMessage","ProtocolVersion":196608,"Parameters":{"database":"postgres","user":"postgres"}}
2023/05/25 09:05:57 PG Recv: {"Type":"AuthenticationSASL","AuthMechanisms":["SCRAM-SHA-256"]}
2023/05/25 09:05:57 PG Send: {"Type":"SASLInitialResponse","AuthMechanism":"SCRAM-SHA-256","Data":"n,,n=,r=du1hqGfLEFgx4XrpnRKsj+9Z"}
2023/05/25 09:05:57 PG Recv: {"Type":"AuthenticationSASLContinue","Data":"r=du1hqGfLEFgx4XrpnRKsj+9ZkUQNMBV3doWl3ycFRUbqtkJ9,s=vxLvuGMsKfKIEl1JRBbsiQ==,i=4096"}
2023/05/25 09:05:57 PG Send: {"Type":"SASLResponse","Data":"c=biws,r=du1hqGfLEFgx4XrpnRKsj+9ZkUQNMBV3doWl3ycFRUbqtkJ9,p=LnAY4FOG73/n5u+lFzU222OCWSmkUn7R1elrIxSYpSk="}
2023/05/25 09:05:58 PG Recv: {"Type":"AuthenticationSASLFinal","Data":"v=vXxebxj0pYh0v/8EySC0zCUEp1XREkpDXHaILk4YfsI="}
2023/05/25 09:05:58 PG Recv: {"Type":"AuthenticationOK"}
2023/05/25 09:05:58 PG Recv: {"Type":"ParameterStatus","Name":"default_transaction_read_only","Value":"off"}
.
i can't use supabase db push
because the remote is the important onemagenta
05/25/2023, 2:24 PM/**
*
* @param url <string> - the Supabase URL string of the image to fetch
* @returns <string> - a URL object string that can be used in an <img src={getImageSm('someImage')}> tag
*
* TODO: string validation
* better return object error handling
*/
export const getPostImage = async (url: string) => {
const { data, error: downloadError } = await imageBucket('images').download(url, {
transform: {
width: 384
}
});
if (downloadError) {
throw downloadError;
}
return URL.createObjectURL(data);
};
Koen
05/25/2023, 2:24 PMhttps://cdn.discordapp.com/attachments/1111298821050335313/1111298821201338388/image.png▾
maikeriva
05/25/2023, 2:37 PMhttps://example.org
, and initially prompts the user to sign in with supabase. When he does so, he is redirected to https://example.org/redirect
, an internal route which first runs an edge function, then redirects again the user to the 3rd party service.
It works fine with email sign-in, but not with oauth providers. After signing in with google, for example, the redirect is invoked... but without the /redirect
part. After some troubleshooting I found out the following:
- The allowed URLs in my supabase control panel are correct
- If I manually browse to https://example.org/redirect
, the page is opened correctly and the app works as intended
- If I change the redirect to another whitelisted static page (so NOT a React SPA), the /redirect
part is appended correctly
- I tested a different hosting provider for the app, and the result did not change
I am thinking it could be because I am implementing this flow as a single page application, but isn't it an extremely common scenario to have with supabase? What might be wrong? Is it a bug?
Thanks for any assistance 🙂Grantly
05/25/2023, 2:56 PMformigueiro
05/25/2023, 3:10 PMvikay
05/25/2023, 3:51 PMhttps://cdn.discordapp.com/attachments/1111320727572979794/1111320727694610432/Screenshot_2023-05-25_211901.png▾
Delyanskiiii
05/25/2023, 3:58 PMhttps://cdn.discordapp.com/attachments/1111322380472680578/1111322381277991003/image.png▾
https://cdn.discordapp.com/attachments/1111322380472680578/1111322381693223022/image.png▾
https://cdn.discordapp.com/attachments/1111322380472680578/1111322382062325852/image.png▾
GaryLake
05/25/2023, 4:31 PMauth.users
to my own account table and joining this to my organisation_users and organisation tables etc – I've got all that and I can attribute what I think is an MAU to an organisation.
Below is a massively simplified version of the query which cuts out all the organisation/user joins and just joins auth.users
to auth.refresh_tokens
select
count(distinct auth.users.email)
from auth.users
inner join auth.refresh_tokens on auth.refresh_tokens.user_id::uuid = auth.users.id
where auth.refresh_tokens.created_at > (current_timestamp - interval '1 months')
You might be asking why I'm joining to refresh_tokens
and not just using auth.users.last_sign_in_at
?
Well I noticed that auth.users.last_sign_in_at
is literally timestamping the last actual sign in and not updating for a returning user like I personally expected (for example, I have a user who was definitely active this month but auth.users.last_sign_in_at
is showing a date in April.
The only thing I could find to test if a user was effectively an MAU this month was to see if they had a refresh token created in the last month... Is this reliable and a good way of doing this?
How does Supabase actually calculate an MAU?
As an aside, is anyone else's MAU reporting in the dashboard under settings > usage showing zero MAUs this month? (I'm meaning to open an ticket)