Skip to main content

Introduction

User authentication and registration made easy.

🎯 What does this module do?

The AuthProvider module handles everything related to user authentication - logging in, signing up, password management, and staying logged in securely.

Think of it as your app's security guard - it checks who's who, lets authorized users in, and keeps the bad guys out.

📖 Simple Explanation

When users want to:

  • 👤 User Registration - Create new user accounts
  • 🔐 Authentication - Login and session management
  • 🔑 Change password
  • 🚪 Log out safely
  • ✉️ Verify email with activation codes
  • 🔒 Security - Password hashing, token management

...this module does all the heavy lifting!

The problem with building user authentication management from scratch:

❌ No password hashing ❌ No validation ❌ No duplicate checking ❌ No email verification ❌ Insecure password comparison ❌ No session management ❌ No rate limiting

Issues:

  • 🔒 Insecure - No password hashing, vulnerable to attacks
  • 📋 No validation - Bad data can be stored
  • 🔄 No authentication - No sessions or tokens
  • 💾 No persistence - Data lost on restart

The AuthProvider solution:

✅ Good - Secure auth management

OneEntry automatically:

  • Hashes password securely
  • Validates email format
  • Checks for duplicates
  • Stores user data persistently
  • Provides authentication tokens

How it works:

User signs up → AuthProvider creates account → Sends activation code via email ✅
User logs in → AuthProvider verifies credentials → Returns access tokens ✅

✨ Key Features

FeatureWhat It DoesExample Use
🔐 User RegistrationCreate new user accountsSign up form
🚪 Login/LogoutAuthenticate usersLogin page
🔑 Password ManagementChange & reset passwordsForgot password flow
🎫 Token ManagementKeep users logged in securelyAuto-refresh sessions
✉️ Email VerificationSend activation codesVerify email after signup
🌍 Multi-languageSupport different languagesInternational apps

Authentication Flow

1. User enters email + password

2. auth() called

3. OneEntry verifies credentials
(Compares hashed passwords)

4. Returns authentication token
(JWT or session token)

5. Token stored client-side
(localStorage, cookie, memory)

6. Token sent with requests
(Authorization header)

7. Token validated by server
(Checks expiration, signature)

📋 What You Need to Know

Authentication Providers

OneEntry supports different ways to authenticate:

  • Email (most common) - traditional email/password
  • Phone (SMS) - authentication via phone number
  • Social (OAuth) - Google, Facebook, etc.

Each provider has an marker (e.g., email for email provider).

Tokens Explained Simply

When a user logs in, they get two tokens:

  • Access Token 🎫 - Like a movie ticket (expires quickly, ~15 minutes)

    • Used for API requests
    • Short-lived for security
  • Refresh Token 🔄 - Like a season pass (lasts longer)

    • Used to get new access tokens
    • Stays valid for days/weeks

Why two tokens? Security! If someone steals the access token, it expires soon.

Form Fields

When registering or updating users, you send form data with:

  • marker - Field name (e.g., "email", "password", "firstName")
  • type - Data type (e.g., "string", "number", "image")
  • value - The actual value

📊 Quick Reference Table - Common Methods

MethodWhat It DoesWhen to Use
auth()Allows you to authenticate users.
changePassword()User password change.
checkCode()Checking the user activation code.
generateCode()Getting the code to activate the user.
getActiveSessionsByMarker()Getting active user sessions data.
getAuthProviderByMarker()Get one auth provider object by marker.
getAuthProviders()Get all auth providers objects.
logout()User account logout.
logoutAll()User account logout on all devices.
oauthSignUp()User registration (authorization) via OAUTH.
refresh()Update user tokens.
signUp()User registration.

❓ Common Questions (FAQ)

Do I need to manage tokens manually?

No! The SDK handles tokens automatically. Just call the methods and the SDK takes care of:

  • Storing tokens
  • Refreshing expired tokens
  • Sending tokens with API requests

How do I keep users logged in after page refresh?

Configure the SDK with saveFunction:

const { AuthProvider } = defineOneEntry("your-url", {
token: "your-token",
auth: {
refreshToken: localStorage.getItem('refreshToken'),
saveFunction: (token) => localStorage.setItem('refreshToken', token)
}
});

What's the difference between login and email?

  • login - can be email OR username (whatever your auth provider accepts)
  • email - always an email address

Can I use social login (Google, Facebook)?

Yes! Set up OAuth providers in OneEntry admin, then use oauthSignUp() method.


How do I handle errors?

Wrap calls in try/catch:

try {
// Success!
} catch (error) {
// Error!
}

What happens when access token expires?

The SDK automatically uses the refresh token to get a new access token. Your users stay logged in seamlessly!


Is it secure?

Yes! OneEntry uses:

  • 🔒 HTTPS encryption
  • 🎫 JWT tokens (industry standard)
  • 🔄 Short-lived access tokens
  • 🔐 Secure password hashing
  • ✉️ Email verification

More information about the module's user interface https://doc.oneentry.cloud/docs/users/auth_provider


Definition of the AuthProvider module


const { AuthProvider } = defineOneEntry(
"your-project-url", {
"token": "your-app-token"
}
);