英文:
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 "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>
</>
);
}
<!-- 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.
<Auth
supabaseClient={supabase}
view="sign_up"
/>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论