PHPackages                             leap-lyhour/lighthouse-graphql-sanctum-auth - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. leap-lyhour/lighthouse-graphql-sanctum-auth

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

leap-lyhour/lighthouse-graphql-sanctum-auth
===========================================

Enterprise-grade Laravel Package for Lighthouse GraphQL with Sanctum Authentication, Spatie Permissions, Multi-Tenancy, 2FA, and Audit Logging

v1.0.0(5mo ago)01MITPHPPHP ^8.2CI failing

Since Nov 17Pushed 5mo agoCompare

[ Source](https://github.com/lyhourdev/lighthouse-graphql-sanctum-auth)[ Packagist](https://packagist.org/packages/leap-lyhour/lighthouse-graphql-sanctum-auth)[ Docs](https://github.com/lyhourdev/lighthouse-graphql-sanctum-auth)[ RSS](/packages/leap-lyhour-lighthouse-graphql-sanctum-auth/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (6)Versions (2)Used By (0)

Lighthouse GraphQL Sanctum Auth / Lighthouse GraphQL Sanctum Auth
=================================================================

[](#lighthouse-graphql-sanctum-auth--lighthouse-graphql-sanctum-auth)

Enterprise-grade Laravel Package that provides Laravel Sanctum Authentication with Lighthouse GraphQL, Spatie Laravel Permission, Multi-Tenant Support, 2FA, Refresh Token System, Device Management, Audit Logging, IP Filtering, Ownership &amp; Row-Level Security.

Laravel Package Enterprise-grade ដែលផ្តល់ Laravel Sanctum Authentication ជាមួយ Lighthouse GraphQL, Spatie Laravel Permission, Multi-Tenant Support, 2FA, Refresh Token System, Device Management, Audit Logging, IP Filtering, Ownership &amp; Row-Level Security។

Features / Features
-------------------

[](#features--features)

- ✅ Laravel Sanctum Authentication (SPA + Token) / Authentication Sanctum (SPA + Token)
- ✅ Lighthouse GraphQL (Queries, Mutations, Directives) / Lighthouse GraphQL (Queries, Mutations, Directives)
- ✅ Spatie Laravel Permission (Roles &amp; Permissions) / Spatie Permission (Roles &amp; Permissions)
- ✅ Multi-Tenant Support (Single DB + Multi DB) / ការគាំទ្រ Multi-Tenant (Single DB + Multi DB)
- ✅ 2FA (Google Authenticator) / 2FA (Google Authenticator) - *Planned* / *គ្រោង*
- ✅ Refresh Token System / ប្រព័ន្ធ Refresh Token
- ✅ Device Management / ការគ្រប់គ្រង Device
- ✅ Audit Logging System / ប្រព័ន្ធ Audit Logging
- ✅ IP Filtering / ការច្រោះ IP - *Planned* / *គ្រោង*
- ✅ Ownership &amp; Row-Level Security / Ownership &amp; Row-Level Security
- ✅ Tenant Resolver (Domain, Header, Token) / Tenant Resolver (Domain, Header, Token)
- ✅ Enterprise Directives / Directives Enterprise:
    - `@hasRole` - Role-based access control / ការគ្រប់គ្រងការចូលប្រើប្រាស់ផ្អែកលើ role
    - `@hasPermission` - Permission-based access control / ការគ្រប់គ្រងការចូលប្រើប្រាស់ផ្អែកលើ permission
    - `@ownership` - Resource ownership verification / ការផ្ទៀងផ្ទាត់ ownership resource
    - `@belongsToTenant` - Multi-tenant isolation / ការញែក multi-tenant
    - `@audit` - Audit logging / Audit logging

Installation / ការដំឡើង
-----------------------

[](#installation--ការដំឡើង)

```
composer require leap-lyhour/lighthouse-graphql-sanctum-auth
```

### Quick Start / ចាប់ផ្តើមរហ័ស

[](#quick-start--ចាប់ផ្តើមរហ័ស)

```
# Install package
# ដំឡើង package
composer require leap-lyhour/lighthouse-graphql-sanctum-auth

# Publish configuration
# Publish configuration
php artisan vendor:publish --tag=lighthouse-sanctum-auth-config

# Publish migrations
# Publish migrations
php artisan vendor:publish --tag=lighthouse-sanctum-auth-migrations

# Run migrations
# ប្រតិបត្តិ migrations
php artisan migrate

# Seed permissions and roles (optional)
# Seed permissions និង roles (ជម្រើស)
php artisan db:seed --class="LeapLyhour\\LighthouseGraphQLSanctumAuth\\Database\\Seeders\\PermissionSeeder"
```

Configuration / ការកំណត់
------------------------

[](#configuration--ការកំណត់)

Publish the configuration file: Publish file កំណត់:

```
php artisan vendor:publish --tag=lighthouse-sanctum-auth-config
```

This will create `config/lighthouse-sanctum-auth.php` in your application. នេះនឹងបង្កើត `config/lighthouse-sanctum-auth.php` ក្នុង application របស់អ្នក។

For detailed configuration options, see [Configuration Guide](./docs/02-configuration.md). សម្រាប់ការកំណត់លម្អិត, មើល [មគ្គុទេសក៍ការកំណត់](./docs/02-configuration.md)។

Usage / ការប្រើ
---------------

[](#usage--ការប្រើ)

### GraphQL Schema / GraphQL Schema

[](#graphql-schema--graphql-schema)

The package provides authentication mutations and queries: Package ផ្តល់ authentication mutations និង queries:

```
type Query {
  me: User @auth
}

type Mutation {
  login(email: String!, password: String!, device_name: String): AuthPayload!
  refreshToken(refresh_token: String!): RefreshTokenPayload!
  logout: Boolean! @auth
}
```

### Authentication Example / ឧទាហរណ៍ Authentication

[](#authentication-example--ឧទាហរណ៍-authentication)

```
# Login
mutation {
  login(
    email: "user@example.com"
    password: "password"
    device_name: "iPhone 14"
  ) {
    user {
      id
      name
      email
      roles {
        name
      }
      permissions {
        name
      }
    }
    token
    token_type
  }
}

# Get current user
query {
  me {
    id
    name
    email
    roles {
      name
    }
    permissions {
      name
    }
  }
}
```

### Directives / Directives

[](#directives--directives)

#### @hasRole

[](#hasrole)

Restrict access to users with specific roles: កំណត់ការចូលប្រើប្រាស់ទៅ users ដែលមាន roles ជាក់លាក់:

```
type Query {
  adminUsers: [User!]! @hasRole(role: "admin")
}

type Mutation {
  deleteUser(id: ID!): User! @hasRole(role: "admin")
}
```

#### @hasPermission

[](#haspermission)

Restrict access to users with specific permissions: កំណត់ការចូលប្រើប្រាស់ទៅ users ដែលមាន permissions ជាក់លាក់:

```
type Mutation {
  deleteUser(id: ID!): User! @hasPermission(permission: "delete users")

  editPost(id: ID!, input: PostInput!): Post!
    @hasPermission(permission: "edit posts")
}
```

#### @ownership

[](#ownership)

Ensure users can only access resources they own: ធានាថា users អាចចូលប្រើ resources ដែលពួកគេជាម្ចាស់ប៉ុណ្ណោះ:

```
type Query {
  myPost(id: ID!): Post @ownership(relation: "user_id")
}

type Mutation {
  updateMyPost(id: ID!, input: PostInput!): Post!
    @ownership(relation: "user_id")
}
```

#### @belongsToTenant

[](#belongstotenant)

Ensure resources belong to the current tenant: ធានាថា resources ជាកម្មសិទ្ធិរបស់ tenant បច្ចុប្បន្ន:

```
type Query {
  posts: [Post!]! @belongsToTenant
}

type Mutation {
  createPost(input: PostInput!): Post! @belongsToTenant
}
```

#### @audit

[](#audit)

Log field access and mutations: កត់ត្រា field access និង mutations:

```
type Mutation {
  deleteUser(id: ID!): User! @audit(action: "delete")

  createPost(input: PostInput!): Post! @audit(action: "create")

  updatePost(id: ID!, input: PostInput!): Post! @audit(action: "update")
}
```

### Combining Directives / ការរួមបញ្ចូល Directives

[](#combining-directives--ការរួមបញ្ចូល-directives)

You can combine multiple directives for enhanced security: អ្នកអាចរួមបញ្ចូល directives ច្រើនសម្រាប់ security កាន់តែប្រសើរ:

```
type Mutation {
  # Requires permission AND logs the action
  # ត្រូវការ permission និងកត់ត្រា action
  deletePost(id: ID!): Post!
    @hasPermission(permission: "delete posts")
    @audit(action: "delete")

  # Requires role AND ownership AND logs
  # ត្រូវការ role និង ownership និងកត់ត្រា
  updateMyPost(id: ID!, input: PostInput!): Post!
    @hasRole(role: "editor")
    @ownership(relation: "user_id")
    @audit(action: "update")
}
```

Requirements / តម្រូវការ
------------------------

[](#requirements--តម្រូវការ)

- PHP &gt;= 8.2
- Laravel &gt;= 12.0
- Lighthouse &gt;= 6.0
- Sanctum &gt;= 4.0
- Spatie Permission &gt;= 6.0

Documentation / Documentation
-----------------------------

[](#documentation--documentation)

Complete documentation is available in the [`docs`](./docs/) directory: Documentation ពេញលេញមាននៅក្នុង directory [`docs`](./docs/):

- 📖 [Installation Guide](./docs/01-installation.md) / [មគ្គុទេសក៍ការដំឡើង](./docs/01-installation.md)
- ⚙️ [Configuration Guide](./docs/02-configuration.md) / [មគ្គុទេសក៍ការកំណត់](./docs/02-configuration.md)
- 🔐 [Authentication Guide](./docs/03-authentication.md) / [មគ្គុទេសក៍ Authentication](./docs/03-authentication.md)
- 👥 [Permissions &amp; Roles Guide](./docs/04-permissions-roles.md) / [មគ្គុទេសក៍ Permissions &amp; Roles](./docs/04-permissions-roles.md)
- 🎯 [Directives Guide](./docs/05-directives.md) / [មគ្គុទេសក៍ Directives](./docs/05-directives.md)
- 🏢 [Multi-Tenancy Guide](./docs/06-multi-tenancy.md) / [មគ្គុទេសក៍ Multi-Tenancy](./docs/06-multi-tenancy.md)
- 📱 [Device Management Guide](./docs/07-device-management.md) / [មគ្គុទេសក៍ការគ្រប់គ្រង Device](./docs/07-device-management.md)
- 🛠️ [Helpers Guide](./docs/08-helpers.md) / [មគ្គុទេសក៍ Helpers](./docs/08-helpers.md)
- 🔧 [Traits &amp; Models Guide](./docs/09-traits-models.md) / [មគ្គុទេសក៍ Traits &amp; Models](./docs/09-traits-models.md)
- 📋 [Audit Logging Guide](./docs/10-audit-logging.md) / [មគ្គុទេសក៍ Audit Logging](./docs/10-audit-logging.md)
- 💻 [Frontend Integration](./docs/14-frontend-integration.md) / [ការរួមបញ្ចូល Frontend](./docs/14-frontend-integration.md)
- 📚 [API Reference](./docs/12-api-reference.md) / [ឯកសារ API](./docs/12-api-reference.md)
- 🐛 [Troubleshooting](./docs/13-troubleshooting.md) / [ការដោះស្រាយបញ្ហា](./docs/13-troubleshooting.md)

Quick Examples / ឧទាហរណ៍រហ័ស
----------------------------

[](#quick-examples--ឧទាហរណ៍រហ័ស)

### User Model Setup / ការរៀបចំ User Model

[](#user-model-setup--ការរៀបចំ-user-model)

```
