Skip to content

Commit

Permalink
πŸ”€ Leaf auth v2
Browse files Browse the repository at this point in the history
Leaf Auth v2
  • Loading branch information
mychidarko authored Jan 24, 2022
2 parents b5aacc1 + 7863ffc commit 3ba37ad
Show file tree
Hide file tree
Showing 10 changed files with 769 additions and 861 deletions.
23 changes: 19 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
test
Experimental
vendor
composer.lock
# Global
.phpunit*
.composer
composer.lock
package-lock.json
vendor/
test/
*.tests.php
workflows

# OS Generated
.DS_Store*
ehthumbs.db
Icon?
Thumbs.db
*.swp

# phpstorm
.idea/*
91 changes: 89 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
<p align="center">
<br><br>
<img src="https://leafphp.netlify.app/assets/img/leaf3-logo.png" height="100"/>
<h1 align="center">Leaf Auth Module</h1>
<h1 align="center">Leaf Auth v2</h1>
<br><br>
</p>

[![Latest Stable Version](https://poser.pugx.org/leafs/auth/v/stable)](https://packagist.org/packages/leafs/auth)
[![Total Downloads](https://poser.pugx.org/leafs/auth/downloads)](https://packagist.org/packages/leafs/auth)
[![License](https://poser.pugx.org/leafs/auth/license)](https://packagist.org/packages/leafs/auth)

Leaf's auth helper packaged as a serve-yourself module.
Leaf auth is a simple but powerful module which comes with powerful functions for handling all your authentication needs.

v2 comes with tons of fixes, improvements and upgrades. Running on top of leaf db v2, it also has support for other database types like PostgreSQL, Sqlite and many more.

## Installation

Expand All @@ -20,6 +22,84 @@ You can easily install Leaf using [Composer](https://getcomposer.org/).
composer require leafs/auth
```

Or with leaf db

```sh
leaf install auth
```

## Basic Usage

After installing leaf auth, you need to connect to your database. v2 presents additional ways to achieve this.

### connect

The connect method allows you to pass in your database connection parameters directly to leaf auth.

```php
auth()->connect('127.0.0.1', 'dbname', 'username', 'password');
```

### autoConnect

This method creates a database connection using your env variables.

```env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=LEAF_DB_NAME
DB_USERNAME=LEAF_DB_USERNAME
DB_PASSWORD=
```

And call `autoConnect` in your app.

```php
auth()->autoConnect();
```

### db connection (v2 only)

Leaf auth now allows you to directly pass a PDO connection into leaf auth. This allows you to share your connection with leaf auth and avoid multiple connections.

```php
$auth = new Leaf\Auth;
$auth->dbConnection($pdoConnecction);
```

This also means that you can share you leaf db v2 connection with leaf auth like this:

```php
$auth = new Leaf\Auth;
$auth->dbConnection($db->connection());
```

### Leaf db (auth v2 + leaf 3 only)

If you are using leaf auth in a leaf 3 app, you will have access to the `auth` global as shown in some of the above connections. Along with this, if you already have a leaf db connection, you no longer need to explicitly connect to your database. Leaf auth searches for a leaf db instance and connects to it automatically.

**Note that this only works in a leaf 3 app and only if you already have a leaf db connection.**

```php
<?php

db()->connect('127.0.0.1', 'dbname', 'username', 'password');

// you can use auth straight away without any connect
auth()->login(...);
```

## πŸ“š Auth methods

After connecting your db, you can use any of the methods below.

WIP: This page will be updated

## ⚑️ Funtional Mode

When using leaf auth in a leaf 3 app, you will have access to the `auth`, `guard`, `hasAuth` and `sessionUser` globals.

## πŸ’¬ Stay In Touch

- [Twitter](https://twitter.com/leafphp)
Expand Down Expand Up @@ -85,6 +165,13 @@ And to all our existing cash/code contributors, we love you all ❀️
<sub><b>Vano</b></sub>
</a>
</td>
<td align="center">
<a href="#">
<img src="https://images.opencollective.com/guest-c72a498e/avatar/256.png" width="120px" alt=""/>
<br />
<sub><b>Casprine</b></sub>
</a>
</td>
</tr>
</table>

Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
"require": {
"leafs/date": "^1.0",
"leafs/password": "^1.0",
"leafs/session": "^1.0",
"leafs/db": "^1.0",
"leafs/form": "^1.0",
"leafs/http": "^1.0"
"leafs/session": "^1.1",
"leafs/db": "^2.0",
"leafs/form": "^1.1",
"leafs/http": "^1.2.1"
}
}
Loading

0 comments on commit 3ba37ad

Please sign in to comment.