Next.js Discord

Discord Forum

Cant understand how buttons with onClick Method work.

Unanswered
Appenzeller Sennenhund posted this in #help-forum
Open in Discord
Avatar
Appenzeller SennenhundOP
I was trying to add a button that runs a function that handles oauth login with supabase :

Button:
<div className="flex flex-col gap-2 [&>input]:mb-3 mt-8">
   <button onClick={() => LoginWithAuth("google")}>Google!</button>
</div>

To use this I had to add "use client"; for it to render the page

LoginWithAuth function:
export const loginWithOauth = async (provider: "google" | "discord") => {
  const supabase = await createClient();

  supabase.auth.signInWithOAuth({
    provider,
  })
  return redirect("/protected");
}


with the way createClient() works, I am having to use async and await. but when I try to use the async function it just tells me:
async/await is not yet supported in Client Components, only Server Components. This error is often caused by accidentally adding'use client'to a module that was originally written for the server.

I am new to next js. I was looking for some documentation on how this can be achieved and what are the best practices failed to find some (don't know what I was supposed to look for). redirecting to some documentation will be helpful.

Thanks in advance! (:

11 Replies

Avatar
supabase createClient is not async
Avatar
Appenzeller SennenhundOP
oh yes, I saw that somewhere earlier. I used their premade example and it looks like this
Image
Avatar
oh nextjs 15 makes it async 😭
Avatar
Appenzeller SennenhundOP
npx create-next-app -e with-supabase
Avatar
thats the server version of the client though. the clientside version doesn't store cookies
Avatar
Appenzeller SennenhundOP
ahh! let me take a look
I dont think I explored the code very well
Avatar
no worries :P
Avatar
Appenzeller SennenhundOP
yes you are right! thanks a lot
Avatar
happy to help