0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-23 20:33:16 -05:00
logto/packages/console/public/get-started/application/react/en-us/step3.md

901 B
Raw Blame History

title subtitle
Sign In 2 steps

Step 1: Setup your login

The Logto React SDK provides you tools and hooks to quickly implement your own authorization flow. First, lets enter your redirect URI

Redirect URI

Add the following code to your web app

import React from "react";
import { useLogto } from '@logto/react';

const SignInButton = () => {
  const { signIn } = useLogto();
  const redirectUrl = window.location.origin + '/callback';

  return <button onClick={() => signIn(redirectUrl)}>Sign In</button>;
};

export default SignInButton;

Step 2: Retrieve Auth Status

import React from "react";
import { useLogto } from '@logto/react';

const App = () => {
	const { isAuthenticated, signIn } = useLogto();

  if !(isAuthenticated) {
		return <SignInButton />
  }

	return <>
		<AppContent />
		<SignOutButton />
	</>
};