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

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

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

问题

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

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

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

  1. import React from "react";
  2. import { Auth } from "@supabase/auth-ui-react";
  3. import { ThemeSupa } from "@supabase/auth-ui-shared";
  4. import { useNavigate } from "react-router-dom";
  5. import IconLogo from "../../img/brand/icononly_nobuffer.png";
  6. import { Link } from "react-router-dom";
  7. import { supabase } from "../../utils/supabase";
  8. export default function Register() {
  9. const navigate = useNavigate();
  10. supabase.auth.onAuthStateChange(async (event, session) => {
  11. console.log("Auth state changed:", event);
  12. if (event === "SIGNED_IN" || event === "USER_UPDATED") {
  13. const { data, error } = await supabase
  14. .from("user_profile")
  15. .select("*")
  16. .eq("user_uid", session.user.id);
  17. if (error) {
  18. console.error("Error fetching user profile:", error);
  19. } else if (data.length === 0) {
  20. await supabase
  21. .from("user_profile")
  22. .insert([{ user_uid: session.user.id, email: session.user.email }]);
  23. }
  24. navigate("/profile");
  25. }
  26. });
  27. return (
  28. <>
  29. <div className="flex min-h-full items-center justify-center py-12 px-4 sm:px-6 lg:px-8">
  30. <div className="w-full max-w-md space-y-8">
  31. <div>
  32. <Link to="/">
  33. <img
  34. className="mx-auto h-12 w-auto"
  35. src={IconLogo}
  36. alt="Your Company"
  37. />
  38. </Link>
  39. <h2 className="mt-6 text-center text-3xl font-bold tracking-tight text-gray-900">
  40. Join GolfLists.com
  41. </h2>
  42. <p className="text-xs sm:text-sm text-gray-500 text-center pt-4">
  43. It's free to register for GolfLists.com Club and it takes 30
  44. seconds to sign up.
  45. </p>
  46. </div>
  47. <Auth
  48. supabaseClient={supabase}
  49. appearance={{
  50. theme: ThemeSupa,
  51. variables: {
  52. default: {
  53. colors: {
  54. brand: "#4f46e5",
  55. brandAccent: "#4f46e5",
  56. },
  57. },
  58. },
  59. }}
  60. theme="auto"
  61. providers={[]}
  62. />
  63. <p className="text-xs sm:text-sm text-gray-500 text-center">
  64. Tempted...but not sure it's for you yet? Read our
  65. <Link to="/blog" className="text-indigo-600">
  66. {" "}blog{" "}
  67. </Link>
  68. to get a feel for the site.
  69. </p>
  70. </div>
  71. </div>
  72. </>
  73. );
  74. }

希望这有助于你控制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 -->

  1. import React from &quot;react&quot;;
  2. import { Auth } from &quot;@supabase/auth-ui-react&quot;;
  3. import { ThemeSupa } from &quot;@supabase/auth-ui-shared&quot;;
  4. import { useNavigate } from &quot;react-router-dom&quot;;
  5. import IconLogo from &quot;../../img/brand/icononly_nobuffer.png&quot;;
  6. import { Link } from &quot;react-router-dom&quot;;
  7. import { supabase } from &quot;../../utils/supabase&quot;;
  8. export default function Register() {
  9. const navigate = useNavigate();
  10. supabase.auth.onAuthStateChange(async (event, session) =&gt; {
  11. console.log(&quot;Auth state changed:&quot;, event);
  12. if (event === &quot;SIGNED_IN&quot; || event === &quot;USER_UPDATED&quot;) {
  13. const { data, error } = await supabase
  14. .from(&quot;user_profile&quot;)
  15. .select(&quot;*&quot;)
  16. .eq(&quot;user_uid&quot;, session.user.id);
  17. if (error) {
  18. console.error(&quot;Error fetching user profile:&quot;, error);
  19. } else if (data.length === 0) {
  20. await supabase
  21. .from(&quot;user_profile&quot;)
  22. .insert([{ user_uid: session.user.id, email: session.user.email }]);
  23. }
  24. navigate(&quot;/profile&quot;);
  25. }
  26. });
  27. return (
  28. &lt;&gt;
  29. &lt;div className=&quot;flex min-h-full items-center justify-center py-12 px-4 sm:px-6 lg:px-8&quot;&gt;
  30. &lt;div className=&quot;w-full max-w-md space-y-8&quot;&gt;
  31. &lt;div&gt;
  32. &lt;Link to=&quot;/&quot;&gt;
  33. &lt;img
  34. className=&quot;mx-auto h-12 w-auto&quot;
  35. src={IconLogo}
  36. alt=&quot;Your Company&quot;
  37. /&gt;
  38. &lt;/Link&gt;
  39. &lt;h2 className=&quot;mt-6 text-center text-3xl font-bold tracking-tight text-gray-900&quot;&gt;
  40. Join GolfLists.com
  41. &lt;/h2&gt;
  42. &lt;p className=&quot;text-xs sm:text-sm text-gray-500 text-center pt-4&quot;&gt;
  43. It&#39;s free to register for GolfLists.com Club and it takes 30
  44. seconds to sign up.
  45. &lt;/p&gt;
  46. &lt;/div&gt;
  47. &lt;Auth
  48. supabaseClient={supabase}
  49. appearance={{
  50. theme: ThemeSupa,
  51. variables: {
  52. default: {
  53. colors: {
  54. brand: &quot;#4f46e5&quot;,
  55. brandAccent: &quot;#4f46e5&quot;,
  56. },
  57. },
  58. },
  59. }}
  60. theme=&quot;auto&quot;
  61. providers={[]}
  62. /&gt;
  63. &lt;p className=&quot;text-xs sm:text-sm text-gray-500 text-center&quot;&gt;
  64. Tempted...but not sure it&#39;s for you yet? Read our
  65. &lt;Link to=&quot;/blog&quot; className=&quot;text-indigo-600&quot;&gt;
  66. {&quot; &quot;}blog{&quot; &quot;}
  67. &lt;/Link&gt;
  68. to get a feel for the site.
  69. &lt;/p&gt;
  70. &lt;/div&gt;
  71. &lt;/div&gt;
  72. &lt;/&gt;
  73. );
  74. }

<!-- end snippet -->

答案1

得分: 1

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

  1. <Auth
  2. supabaseClient={supabase}
  3. view="sign_up"
  4. />
英文:

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

  1. &lt;Auth
  2. supabaseClient={supabase}
  3. view=&quot;sign_up&quot;
  4. /&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:

确定