Setup Authentication
Saves 16 hours of work

Everything for handling authenticating users

Prerequisites

  • GateUI Installed

If you haven't installed GateUI yet, follow the GateUI installation guide.

Installation

  1. Open your terminal
  2. Navigate to your project folder
  3. Run the following command:
js
npx @gateui/cli add auth

This will copy all the authentication code to your codebase. Continue below to see more in details what is added to the codebase.

How to use

All you need to do is use the LoginWithMagicLink component in where you want the login to be such as in a /login route or modal.

Example Login Page

jsx
import { LoginWithMagicLink } from "@/components/auth";
jsx
import { getUser } from "@/lib/auth";
jsx
jsx
export default async function LoginPage() {
jsx
// --- STATE ---
jsx
const isLoggedIn = Boolean(await getUser())
jsx
jsx
// --- RENDER ---
jsx
if(isLoggedIn) {
jsx
// redirect to homepage
jsx
}
jsx
jsx
return (<div>
jsx
<h1>Welcome to MyApp</h1>
jsx
jsx
<LoginWithMagicLink enabledProviders={["google"]} />
jsx
</div>)
jsx
}

API Overview

All the necessary code has been installed in the following places:

CategoryLocationDetails
Components@/components/auth/Exports: LoginWithMagicLink, Logout
Note: Only Login with magic link or social providers are currently enabled. Signup is not needed since MagicLink automatically creates a user.
Lib@/lib/authExports: getUser, loginWithProvider, loginWithMagicLink, logout
Routes/auth/callback-

Next Steps: User Management (optional)

Learn how to install user management features such as user profile.

User Management

Need Help?

If you encounter any issues, please open an issue on my GitHub repository. I'll respond as soon as possible.

Additional Resources