A-PRYME
01/26/2023, 12:05 AMarrayContainsAny
query?
Also, is it possible to match a column against multiple values? i.e I have a list of ages 42, 46 and 48. I want to fetch users who's ages match any one of the three, how can I achieve this?jakeAnon
01/26/2023, 12:18 AM1voy
01/26/2023, 12:22 AMconst logout = async () => {
await supabase.auth.signOut();
router.push('/');
};
return (
<div className='flex-col flex-wrap items-center justify-center w-full max-w-3xl px-2 mx-auto my-16 text-center'>
{lessons &&
lessons.map((lesson) => (
<Link
key={lesson.id}
href={lesson.id.toString()}
className='flex h-40 p-8 mb-4 text-xl rounded shadow'
>
{lesson.title}
</Link>
))}
{user ? (
<div>
<h1>User is logged in with: {user.email}</h1>
<Image
alt='avatar'
src={`${user.user_metadata.avatar_url}`}
width={30}
height={30}
/>
<h2>Allow access to post on your behalf:</h2>
<button
className='p-2 font-black tracking-tighter text-white bg-black rounded-xl'
onClick={() => logout()}
>
Signout
</button>
</div>
) : (
)}
</div>
);
}
export const getServerSideProps = async (ctx: GetServerSidePropsContext) => {
// Create authenticated Supabase Client
const supabase = createServerSupabaseClient(ctx);
// Check if we have a session
const {
data: { session },
} = await supabase.auth.getSession();
const { data: lessons }: PostgrestResponse<any> = await supabase
.from('lesson')
.select('*');
if (!session)
return {
props: {
user: false,
},
};
return {
props: {
initialSession: session,
user: session.user,
lessons,
},
};
};
fast
01/26/2023, 12:36 AMconst router = useRouter();
const supabaseUser = useUser();
React.useEffect(() => {
if(supabaseUser) {
//Allow the user enter the admin dashboard
} else {
//Redirect user to login page
router.push("/login");
}
}, [supabaseUser]);
^ The problem with that is that the user object need some amount of time to load but the useEffect Hook is called before the user is loaded so the user gets redirected. I am coming from firebase where I've used such hooks for such cases.Vik
01/26/2023, 12:41 AMfollowers
table for my project. My goal is to allow reading of a users followers if their account is not set to private.
profiles table:
id: uuid
...
private: boolean
followers table:
id: int8
user_id: FK profiles ID
followee_id: FK profiles ID
So anytime a user follows someone a record is created in the followers table. The user_id
column is the user being followed and the followee_id
is the person that followed them.
I want to setup a policy so if the users account is private you will only be able to see their list if you are already following them, aka a record exists. If their account is private and you don't already follow them, nothing should be returned.
I've never created a policy based on a FK's table column, so this will be a learning experience for me.pickwickian
01/26/2023, 12:43 AMupdate
method to insert the JSON into the column. The example given for this in the documentation is confusing.
It looks like if you want to treat your whole row like JSON. But only one of my columns is JSONB. I have it as a JS Object. I'm not sure what I am doing wrong and there's no error spitting out. I tried to update it like their docs where I named the column and used template literal to pass the value in. That didn't work (screenshot attached) and I tried a more conventional route. I feel like if it's not updating, it should be displaying something for the error.herropaul
01/26/2023, 12:43 AMAuth
component to redirect users to a specific path after they log in, but it's not working. I've provided the path in the URL configuration tab in my Supabase dashboard and defined it in my NextJS pages
directory as well (pages/users/index.tsx
), but it's still not redirecting. Has anyone else had this issue or have any suggestions?
Here are some github issues I found as well but haven't been working for me.
https://github.com/supabase/supabase/discussions/6088
https://github.com/supabase/auth-elements/issues/12Cool Bean
01/26/2023, 2:13 AMInASunshineState
01/26/2023, 2:24 AMelliott
01/26/2023, 2:54 AMKamael愛
01/26/2023, 7:00 AMCody
01/26/2023, 7:04 AM${fence}
01/26/2023, 7:35 AMLukas
01/26/2023, 8:00 AMuseSession()
, provider_token is filled with a provider token. After a bit, it becomes null. I was wondering what the best way to proceed is. Should I just store the provider token in localstorage? If I do, how long will that take to get invalidated (as it still seems to work if I copy and paste it out).lake_mattiato
01/26/2023, 9:48 AMharshcut
01/26/2023, 9:58 AMpetoma
01/26/2023, 10:06 AMSimonPotvin
01/26/2023, 12:10 PMKen
01/26/2023, 12:19 PMFlayy
01/26/2023, 12:44 PMsignInWithPassword()
which returns Promise<AuthResponse>
. Now when there won't be any auth error what needs to happen for user to be null?
ts
export type AuthResponse =
| {
data: {
user: User | null // <-----------I mean this null
session: Session | null
}
error: null
}
| {
data: {
user: null
session: null
}
error: AuthError
}
Is there some edge case I need to handle? Or I can just assume that user
will be always set and it is just a general type used in many places?Nafets
01/26/2023, 1:05 PMDbugger
01/26/2023, 1:50 PM-- Create a table for public profiles
create table profiles (
id uuid references auth.users on delete cascade not null primary key,
updated_at timestamp with time zone,
username text unique,
full_name text,
avatar_url text,
website text,
constraint username_length check (char_length(username) >= 3)
);
-- This trigger automatically creates a profile entry when a new user signs up via Supabase Auth.
create function public.handle_new_user()
returns trigger as $$
begin
insert into public.profiles (id, full_name, avatar_url)
values (new.id, new.raw_user_meta_data->>'full_name', new.raw_user_meta_data->>'avatar_url');
return new;
end;
$$ language plpgsql security definer;
create trigger on_auth_user_created
after insert on auth.users
for each row execute procedure public.handle_new_user();
But the problem now is that, I want the user to decide his username on Signup. I am using the helpers from @supabase/auth-ui-react
, but I do not see any way to alter it, so that it fits my needs.
What do you recommend me? Do I need to build my own Auth forms?garyaustin
01/26/2023, 3:12 PMpigeatgarlic
01/26/2023, 2:56 PMArthesius
01/26/2023, 3:09 PMts
Property 'channel' does not exist on type 'SupabaseClient'.
any
Kuba
01/26/2023, 4:02 PMjson
"@supabase/auth-helpers-nextjs": "^0.5.4",
"@supabase/auth-helpers-react": "^0.3.1",
"@supabase/auth-ui-react": "^0.2.6",
"@supabase/supabase-js": "^2.4.1"
I'm currently testing Supabase with the example provided in auth-helpers
repo for Next.js (https://github.com/supabase/auth-helpers/tree/main/examples/nextjs).
However, trying to sign-in with a GitHub does nothing. The request happens in the background (app goes to GH, authenticates, and redirects back to /
). Is is the intended behavior or rather a bug?Mathew
01/26/2023, 4:07 PMfelixthehat
01/26/2023, 4:09 PMsupabase.auth.signInWithPassword
method, but that throws the following error. Do I have to enable something to allow sign in with password? thanks!
ode 500
msg "Database error saving new user"
error_id "78fa69da17f20755-MAN"
A-PRYME
01/26/2023, 4:19 PMservice cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth != null;
}
}
}
What is the equivalent of this with Supabase?