Is there a `withoutAuthRequired()` based on https:...
# help
s
Is there a
withoutAuthRequired()
based on https://github.com/supabase-community/supabase-auth-helpers/blob/next/src/nextjs/README.md#server-side-rendering-ssr---withauthrequired to ensure that a login page is accessible only if the user hasn't logged in?
n
Hello @sbr! This thread has been automatically created from your message in #843999948717555735 a ``few seconds ago``. Pinging @User so that they see this as well! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ... menu) and select Leave Thread to unsubscribe from future updates. Want to change the title? Use the
/title
command! We have solved your problem? Click the button below to archive it.
s
in such cases, you need to call the function withAuthRequired and render the page as is
n
sbr (2022-04-01)
s
Hi @User! Thanks for your reply! But if I call
withAuthRequired
then won't the page render only if the user if authenticated? Here is my usecase in a bit more detail- -
/login
should be shown only if a user is not authenticated - If a user is authenticated then
/login
should redirect to
/home
-
/home
should be shown only if a user is authenticated - If a user is not authenticated then
/home
should redirect to
/login
The last two points can be done with
withAuthRequired
. How can the first two points be implemented?
s
Copy code
//something like this
const SignUp = () => {
  const router = useRouter();
  const [email, setEmail] = useState('');
  const [password, setPassword] = useState('');

  const handleSubmit = async (e: React.FormEvent) => {
    e.preventDefault();

    const { data } = await supabase.auth.signUp({
      email,
      password,
    });

    if (data) {
      router.push('/dashboard');
    } else {
      router.push('/signin');
    }
  };
this is just a reference - not the actual code