Skip to content

# Repository

## `` jwtlib.repository

### Summary

UserRepository: Persistence layer for authentication.

This module defines the MongoDB-backed repository for managing user records, including creation, lookup, and credential verification.

### Classes

#### `` UserRepository

    1

    UserRepository()

Bases: `BaseRepository[User]`

MongoDB-backed repository for `User` documents.

Notes

Responsibilities:

    1
    2

    - Manage user persistence (CRUD).
    - Handle credential verification and token issuance.

##### Functions

###### `` authenticate_user `async`

    1

    authenticate_user(user_auth: LoginRequest) -> Optional[dict]

Verify user credentials and prepare a login response.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`user_auth` | `LoginRequest` | Login credentials. | required

Returns:

Type | Description
--- | ---
`Optional[dict]` | dict | None: A dictionary containing the access token and public user if successful, otherwise None.

###### `` create `async`

    1

    create(user_create: RegisterRequest) -> PublicUser

Create a new user record.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`user_create` | `RegisterRequest` | Registration data including prospective password. | required

Returns:

Name | Type | Description
--- | --- | ---
`PublicUser` | `PublicUser` | A PublicUser representation of the created user.

###### `` get_active_users `async`

    1

    get_active_users(skip: int = 0, limit: int = 100) -> List[User]

List all active users with pagination.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`skip` | `int` | Number of records to skip. | `0`
`limit` | `int` | Maximum number of records to return. | `100`

Returns:

Type | Description
--- | ---
`List[User]` | List[User]: A list of active User documents.

###### `` get_by_email `async`

    1

    get_by_email(email: str) -> Optional[User]

Retrieve a user by their unique email address.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`email` | `str` | The email address to search for. | required

Returns:

Type | Description
--- | ---
`Optional[User]` | Optional[User]: The User document if found, otherwise None.

###### `` get_by_username `async`

    1

    get_by_username(username: str) -> Optional[User]

Retrieve a user by their unique username.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`username` | `str` | The username to search for. | required

Returns:

Type | Description
--- | ---
`Optional[User]` | Optional[User]: The User document if found, otherwise None.

### Functions