Instantly Add User Authentication to Your React Projects With Easybase’s <Auth /> Component

User Authentication can be a difficult module to implement and manage in web and mobile applications. There’s a lot to consider when it comes to security, JWTs, salting, and much more.

Fortunately, this can be accomplished instantly with the <Auth …


This content originally appeared on DEV Community and was authored by Michael Bagley

User Authentication can be a difficult module to implement and manage in web and mobile applications. There's a lot to consider when it comes to security, JWTs, salting, and much more.

Fortunately, this can be accomplished instantly with the <Auth /> component (<NativeAuth /> for React Native) from the 'easybase-react' package.

The final result will look like this:

export default function App() {
  return (
    <EasybaseProvider ebconfig={ebconfig}>
      <Auth>
        <h2>You're In!</h2>
      </Auth>
    </EasybaseProvider>
  );
}

Easybase Auth

The Process

Create a free account at easybase.io and make a Project. From there, download your ebconfig token and place it in your React project's src/ folder. Install the package with npm i easybase-react.

Easybase auth 3

Import this config file, along with EasybaseProvider and Auth:

import ebconfig from './ebconfig';
import { EasybaseProvider, Auth } from 'easybase-react';

Wrap your entire component in EasybaseProvider and place Auth inside of it. Children of Auth will only be loaded and displayed if a user is currently signed in.

export default function App() {
  return (
    <EasybaseProvider ebconfig={ebconfig}>
      <Auth>
        <h2>You're In!</h2>
      </Auth>
    </EasybaseProvider>
  );
}

Run your project and create an example account by clicking 'No Account? Sign Up':

Easybase auth 4

This will sign you in! The <Auth /> component is highly customizable when it comes to CSS and forms, read here for customization.

To sign out, import useEasybase and call the signOut function:

function User() {
  const { signOut } = useEasybase()
  return <button onClick={signOut}>Sign Out</button>
}

export default function App() {
  return (
    <EasybaseProvider ebconfig={ebconfig}>
      <Auth>
        <User />
      </Auth>
    </EasybaseProvider>
  );
}

All users will appear in the Easybase interface, under the Users tab:

Easybase auth 5

For a more in-depth reference, check out the full walkthrough here.


This content originally appeared on DEV Community and was authored by Michael Bagley


Print Share Comment Cite Upload Translate Updates
APA

Michael Bagley | Sciencx (2021-06-09T23:15:08+00:00) Instantly Add User Authentication to Your React Projects With Easybase’s <Auth /> Component. Retrieved from https://www.scien.cx/2021/06/09/instantly-add-user-authentication-to-your-react-projects-with-easybases-auth-component/

MLA
" » Instantly Add User Authentication to Your React Projects With Easybase’s <Auth /> Component." Michael Bagley | Sciencx - Wednesday June 9, 2021, https://www.scien.cx/2021/06/09/instantly-add-user-authentication-to-your-react-projects-with-easybases-auth-component/
HARVARD
Michael Bagley | Sciencx Wednesday June 9, 2021 » Instantly Add User Authentication to Your React Projects With Easybase’s <Auth /> Component., viewed ,<https://www.scien.cx/2021/06/09/instantly-add-user-authentication-to-your-react-projects-with-easybases-auth-component/>
VANCOUVER
Michael Bagley | Sciencx - » Instantly Add User Authentication to Your React Projects With Easybase’s <Auth /> Component. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/06/09/instantly-add-user-authentication-to-your-react-projects-with-easybases-auth-component/
CHICAGO
" » Instantly Add User Authentication to Your React Projects With Easybase’s <Auth /> Component." Michael Bagley | Sciencx - Accessed . https://www.scien.cx/2021/06/09/instantly-add-user-authentication-to-your-react-projects-with-easybases-auth-component/
IEEE
" » Instantly Add User Authentication to Your React Projects With Easybase’s <Auth /> Component." Michael Bagley | Sciencx [Online]. Available: https://www.scien.cx/2021/06/09/instantly-add-user-authentication-to-your-react-projects-with-easybases-auth-component/. [Accessed: ]
rf:citation
» Instantly Add User Authentication to Your React Projects With Easybase’s <Auth /> Component | Michael Bagley | Sciencx | https://www.scien.cx/2021/06/09/instantly-add-user-authentication-to-your-react-projects-with-easybases-auth-component/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.