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
- Open your terminal
- Navigate to your project folder
- Run the following command:
jsnpx @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
jsximport { LoginWithMagicLink } from "@/components/auth";jsximport { getUser } from "@/lib/auth";jsxjsxexport default async function LoginPage() {jsx// --- STATE ---jsxconst isLoggedIn = Boolean(await getUser())jsxjsx// --- RENDER ---jsxif(isLoggedIn) {jsx// redirect to homepagejsx}jsxjsxreturn (<div>jsx<h1>Welcome to MyApp</h1>jsxjsx<LoginWithMagicLink enabledProviders={["google"]} />jsx</div>)jsx}
API Overview
All the necessary code has been installed in the following places:
Category | Location | Details |
---|---|---|
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/auth | Exports: getUser, loginWithProvider, loginWithMagicLink, logout |
Routes | /auth/callback | - |
Next Steps: User Management (optional)
Learn how to install user management features such as user profile.
User ManagementNeed Help?
If you encounter any issues, please open an issue on my GitHub repository. I'll respond as soon as possible.