# Credentials

## **Scenario 1: Sign up/Sign in with Free Account**

**Responsible File**: `action/sign-up.ts`

**Steps**:

1. **Inputs Validation**
2. **User Record Creation**: Hash the password before saving.
3. **Verification Token Generation**
4. **Send Verification Email**:
   * User receives a link in the form: `auth/sign-up?token=token_code`
   * The link performs automatic validation and informs the user of the result (success or error).

**Final Steps**:

1. **ClientPlan Creation**: In the function (`actions/auth/new-email-verification.ts`), handle the `ClientPlan` creation and call `handleAfterSignupTasks()`.

## **Scenario 2: Sign up as a New Client Who Has Just Subscribed to a Plan**

This scenario is similar to the OAuth-based scenario for new clients with subscription plans.

1. **PreClientPlan Table**: Created at the Stripe webhook level to store temporary plan information.
2. **Token-based Link**: Sent to the client for account creation.

   **Link Format**: `example.com/auth/sign-up?token=token_code`
3. In the `action/sign-up.ts` file, handle the token and proceed to set up the client’s account in the `setupUserAccount()` function.
4. Use the token to extract data from the `PreClientPlan` record and create the `ClientPlan`.

   ```jsx
   await prisma.clientPlan.create({
       data: {
           userId,
           subscriptionPlan: existingPreClientPlan.plan,
           status: "ACTIVE",
           subscriptionType: existingPreClientPlan.subscriptionType,
           // ...other fields
       },
   });
   ```
5. Finally, call `handleAfterSignupTasks()` to complete the process.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://zakariaes-organization.gitbook.io/saascore-docs/authentication-flow/for-clients/credentials.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
