Skip to content

Commit

Permalink
📝 Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
juliomotol committed Jan 7, 2021
1 parent 518f910 commit ed0a4b0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
### Added
- PHP 8 Support.

### Changed
- AuthTimeout now uses `carbon\carbon` to check and store timeout sessions.

### Removed
- Removed `auth-timeout.redirect` in favor of `AuthTimeoutMiddleware::redirectTo()`.
- If you are using this config key, we highly suggest to use `AuthTimeoutMiddleware::redirectTo()` as it provides much better flexibility.

## v2.2.1 (2020-10-12)

Expand Down
26 changes: 12 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Laravel Auth Timeout

[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![StyleCI](https://github.styleci.io/repos/252781961/shield?branch=master)](https://github.styleci.io/repos/252781961)
[![Latest Version on Packagist](https://img.shields.io/packagist/v/juliomotol/laravel-auth-timeout.svg?style=flat-square)](https://packagist.org/packages/juliomotol/laravel-auth-timeout)
[![Total Downloads](https://img.shields.io/packagist/dt/juliomotol/laravel-auth-timeout.svg?style=flat-square)](https://packagist.org/packages/juliomotol/laravel-auth-timeout)

A small Laravel 6+ package that handles Authentication Timeouts.
A small Laravel 8 package that handles Authentication Timeouts.

When upgrading to v2, please see the [CHANGELOG.md](./CHANGELOG.md).
When upgrading to v3, please see the [CHANGELOG.md](./CHANGELOG.md).

> For Laravel 6+ support, see [v2](https://github.com/juliomotol/laravel-auth-timeout/tree/v2).
## Why Laravel Auth Timeout?

Expand Down Expand Up @@ -52,11 +53,10 @@ php artisan vendor:publish --provider="JulioMotol\AuthTimeout\ServiceProvider"

### Content of the configuration

| Key | Default value | Description |
| -------- | ---------------------- | ---------------------------------------------------------------------------------------------------- |
| session | `"last_activity_time"` | The name of the session token to be used. |
| timeout | `15` | The timeout duration in minutes. |
| redirect | `null` | The path to redirect the user when timed out. (For more flexibilty, see [Redirection](#redirection)) |
| Key | Default value | Description |
| ------- | ---------------------- | ----------------------------------------- |
| session | `"last_activity_time"` | The name of the session token to be used. |
| timeout | `15` | The timeout duration in minutes. |

## Usage

Expand Down Expand Up @@ -98,7 +98,7 @@ Route::get('/admin', [
### AuthTimeoutEvent

The `AuthTimeoutMiddleware` will dispatch an `AuthTimeoutEvent` every time a user has timed out. You can assign a listener for this event in your `EventServiceProvider`.
An `AuthTimeoutEvent` will dispatch every time a user has timed out. You can assign a listener for this event in your `EventServiceProvider`.

```php
protected $listen = [
Expand All @@ -123,9 +123,7 @@ class FooEventListener

### Redirection

For a simple and straight forward redirection, you can [publish the config file](#config) and change the `redirect` option to where you want to redirect the user when they timed out.

Alternatively, you can extend the `AuthTimeoutMiddleware` then override the `redirectTo()` method to provide much flexibility.
To modify the redirection when a user has timed out, you'll need extend the `AuthTimeoutMiddleware` then override the `redirectTo()` method.

```php
<?php
Expand All @@ -140,9 +138,9 @@ class AuthTimeoutMiddleware extends BaseMiddleware
* Get the path the user should be redirected to when they timed out.
*
* @param \Illuminate\Http\Request $request
* @param mixed $guard
* @param mixed $guard
*
* @return string|null
* @return mixed
*/
protected function redirectTo($request, $guard = null)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Middleware/AuthTimeoutMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ public function __construct(AuthManager $auth, AuthTimeout $authTimeout)
* @param \Closure $next
* @param string $guard
*
* @return \Symfony\Component\HttpFoundation\Response
* @throws Illuminate\Auth\AuthenticationException
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function handle($request, Closure $next, $guard = null)
{
Expand All @@ -55,8 +56,7 @@ public function handle($request, Closure $next, $guard = null)
// First we'll initialize a session when none has been set yet.
$this->authTimeout->init();

// Then we'll check if the user have timed out. If so, we'll throw an
// AuthenticationException.
// Then we'll check if the user have timed out.
if (! $this->authTimeout->check($guard)) {
throw new AuthenticationException('Timed out.', [$guard], $this->redirectTo($request, $guard));
}
Expand Down

0 comments on commit ed0a4b0

Please sign in to comment.