# Creator Sign In & Authentication (/login)

> The authentication gateway for NoCodeVista creators. Provides secure passwordless access via Magic Links and OTP codes, Google OAuth SSO, and automatic merging of guest-generated websites.

## 1. Screen Purpose & Capabilities

The /login screen is the secure authentication portal for NoCodeVista. It provides passwordless, instant access for creators to manage their published websites, configure custom domains, view analytics, and edit web projects.

Key capabilities:
- Passwordless authentication: eliminates passwords via one-time passcodes (OTP) and email magic links.
- Single Sign-On (SSO): instant one-click login with Google accounts.
- Guest Account Merge: automatically transfers websites created on /start into the authenticated account.
- Dynamic Post-Login Routing: smoothly redirects creators back to their active canvas or dashboard.

## 2. Authentication Methods

Creators can authenticate through two secure methods:

1. Email Magic Link & 6-Digit OTP:
   - Creator enters their email address.
   - A secure 6-digit verification code and a one-click Magic Link are sent immediately to their inbox.
   - Entering the 6-digit code or clicking the magic link signs the user in instantly.
   - Eliminates forgotten passwords, credential stuffing, and insecure passwords.

2. Google OAuth 2.0 Sign-In:
   - Creator clicks "Continue with Google".
   - Authenticates through Google Identity Services.
   - Provides instant access with existing verified credentials.

## 3. Guest Website Merge Protocol

NoCodeVista allows creators to build websites first on /start before creating an account. The login screen handles account merging automatically:

1. If an anonymous user generates a website, their session token is saved in localStorage as isGuest: true.
2. When the user navigates to /login, their token is preserved in localStorage as guestTokenToMerge.
3. Upon successful email OTP verification or Google SSO, the authentication service calls the account merge endpoint.
4. All websites, schemas, and configurations created during the guest session are claimed by and attached to the user permanent account.
5. The guest flag is cleared, and the creator is transitioned to a full authenticated session without losing any work.

## 4. Session Security & Token Lifecycle

- JWT Bearer Tokens: authentication responses issue a secure JSON Web Token stored in localStorage.authToken.
- Expiration: session tokens carry a standard 30-day lifetime with sliding refresh.
- Rate Limiting: auth endpoints enforce strict rate limits per IP and email to prevent brute-force attacks.
- Session Expiry Detection: client axios interceptors detect 401 Unauthorized responses and guide creators through re-authentication without losing canvas edits.

## 5. Redirect Parameters & Navigation Flow

The login screen respects contextual redirect parameters:

- ?redirect=<path>: returns the creator directly to their intended target (e.g. ?redirect=/page-builder returns to the active website editor).
- ?token=<magicToken>: allows instant authentication directly from email magic links without manual OTP typing.
- Default destination: if no redirect parameter is present, authenticated creators are routed to /websites (Creator Dashboard).
