Supabase Auth UI:显示注册界面而不是登录界面?

huangapple go评论84阅读模式
英文:

Supabase Auth UI: show the sign up UI not the sign in UI?

问题

我正在使用Supabase Auth UI作为我的网站的登录/注册身份验证提供程序。

目前,Auth UI始终显示登录按钮。我可以通过成功单击“没有帐户?注册”来进入注册界面。从技术上讲,所有登录和注册都可以正常工作,但我希望能够显示注册页面(例如,对于我的注册按钮),以便用户不会认为他们正在注册,并在他们意识到他们正在尝试登录时不必重新输入他们的详细信息。

似乎允许我控制UI的哪一部分显示是一个很明显的选择,但我找不到方法来做到这一点?

import React from "react";
import { Auth } from "@supabase/auth-ui-react";
import { ThemeSupa } from "@supabase/auth-ui-shared";
import { useNavigate } from "react-router-dom";
import IconLogo from "../../img/brand/icononly_nobuffer.png";
import { Link } from "react-router-dom";
import { supabase } from "../../utils/supabase";

export default function Register() {
  const navigate = useNavigate();

  supabase.auth.onAuthStateChange(async (event, session) => {
    console.log("Auth state changed:", event);
    if (event === "SIGNED_IN" || event === "USER_UPDATED") {
      const { data, error } = await supabase
        .from("user_profile")
        .select("*")
        .eq("user_uid", session.user.id);

      if (error) {
        console.error("Error fetching user profile:", error);
      } else if (data.length === 0) {
        await supabase
          .from("user_profile")
          .insert([{ user_uid: session.user.id, email: session.user.email }]);
      }

      navigate("/profile");
    }
  });

  return (
    <>
      <div className="flex min-h-full items-center justify-center py-12 px-4 sm:px-6 lg:px-8">
        <div className="w-full max-w-md space-y-8">
          <div>
            <Link to="/">
              <img
                className="mx-auto h-12 w-auto"
                src={IconLogo}
                alt="Your Company"
              />
            </Link>
            <h2 className="mt-6 text-center text-3xl font-bold tracking-tight text-gray-900">
              Join GolfLists.com
            </h2>
            <p className="text-xs sm:text-sm text-gray-500 text-center pt-4">
              It's free to register for GolfLists.com Club and it takes 30
              seconds to sign up.
            </p>
          </div>
          <Auth
            supabaseClient={supabase}
            appearance={{
              theme: ThemeSupa,
              variables: {
                default: {
                  colors: {
                    brand: "#4f46e5",
                    brandAccent: "#4f46e5",
                  },
                },
              },
            }}
            theme="auto"
            providers={[]}
          />
          <p className="text-xs sm:text-sm text-gray-500 text-center">
            Tempted...but not sure it's for you yet? Read our
            <Link to="/blog" className="text-indigo-600">
              {" "}blog{" "}
            </Link>
            to get a feel for the site.
          </p>
        </div>
      </div>
    </>
  );
}

希望这有助于你控制Auth UI 中的注册和登录页面。

英文:

I am using Supabase Auth UI as the login / sign up auth provider for my website.

Currently the Auth UI always shows the login button. I can get onto the sign up UI by clicking "Don't have an account? Sign up" successfully. All the log in and sign up works technically, but I want to be able to show the sign up page (e.g. for my sign up button) so that a user doesn't think they are registering and have to re-do their details when they realise they are trying to sign in.

Seems a no brainer to allow me to control which bit of the UI shows, but I can't find a way to do it?

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

import React from &quot;react&quot;;
import { Auth } from &quot;@supabase/auth-ui-react&quot;;
import { ThemeSupa } from &quot;@supabase/auth-ui-shared&quot;;
import { useNavigate } from &quot;react-router-dom&quot;;
import IconLogo from &quot;../../img/brand/icononly_nobuffer.png&quot;;
import { Link } from &quot;react-router-dom&quot;;
import { supabase } from &quot;../../utils/supabase&quot;;
export default function Register() {
const navigate = useNavigate();
supabase.auth.onAuthStateChange(async (event, session) =&gt; {
console.log(&quot;Auth state changed:&quot;, event);
if (event === &quot;SIGNED_IN&quot; || event === &quot;USER_UPDATED&quot;) {
const { data, error } = await supabase
.from(&quot;user_profile&quot;)
.select(&quot;*&quot;)
.eq(&quot;user_uid&quot;, session.user.id);
if (error) {
console.error(&quot;Error fetching user profile:&quot;, error);
} else if (data.length === 0) {
await supabase
.from(&quot;user_profile&quot;)
.insert([{ user_uid: session.user.id, email: session.user.email }]);
}
navigate(&quot;/profile&quot;);
}
});
return (
&lt;&gt;
&lt;div className=&quot;flex min-h-full items-center justify-center py-12 px-4 sm:px-6 lg:px-8&quot;&gt;
&lt;div className=&quot;w-full max-w-md space-y-8&quot;&gt;
&lt;div&gt;
&lt;Link to=&quot;/&quot;&gt;
&lt;img
className=&quot;mx-auto h-12 w-auto&quot;
src={IconLogo}
alt=&quot;Your Company&quot;
/&gt;
&lt;/Link&gt;
&lt;h2 className=&quot;mt-6 text-center text-3xl font-bold tracking-tight text-gray-900&quot;&gt;
Join GolfLists.com
&lt;/h2&gt;
&lt;p className=&quot;text-xs sm:text-sm text-gray-500 text-center pt-4&quot;&gt;
It&#39;s free to register for GolfLists.com Club and it takes 30
seconds to sign up.
&lt;/p&gt;
&lt;/div&gt;
&lt;Auth
supabaseClient={supabase}
appearance={{
theme: ThemeSupa,
variables: {
default: {
colors: {
brand: &quot;#4f46e5&quot;,
brandAccent: &quot;#4f46e5&quot;,
},
},
},
}}
theme=&quot;auto&quot;
providers={[]}
/&gt;
&lt;p className=&quot;text-xs sm:text-sm text-gray-500 text-center&quot;&gt;
Tempted...but not sure it&#39;s for you yet? Read our
&lt;Link to=&quot;/blog&quot; className=&quot;text-indigo-600&quot;&gt;
{&quot; &quot;}blog{&quot; &quot;}
&lt;/Link&gt;
to get a feel for the site.
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/&gt;
);
}

<!-- end snippet -->

答案1

得分: 1

如果您只想显示注册视图,可以将其作为组件的属性传递值。

<Auth
  supabaseClient={supabase}
  view="sign_up"
/>
英文:

If you only want to show the sign up view you can pass that as a value to the component as a prop.

&lt;Auth
supabaseClient={supabase}
view=&quot;sign_up&quot;
/&gt;

huangapple
  • 本文由 发表于 2023年7月17日 20:10:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76704330.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定