spiderwebtr/
isauth
g4t.io

Prompt Users to Login When they Have an Expired Session with the isAuth Package

133 stars by Paul Redmond

Laravel IsAuth is a Laravel package by Emre Dipi that provides control to check if a user session is dead before submitting forms. If the session is dead, a mod…

README from spiderwebtr/isauth Open on GitHub →

isAuth

alt text alt text alt text alt text alt text

This package provides control to check if user session dead before submit forms. If the session is dead, a modal will reveal and ask password to re-login.

Demo

Demo Source

1- Installation

Require this package with composer.

composer require spiderwebtr/isauth

1.2- Laravel < 5.5

If you don't use auto-discovery, add the ServiceProvider to the providers array in config/app.php

spiderwebtr\isauth\isAuthServiceProvider::class,

2- Create assets and config file

Run the command to create the js and config files.

php artisan vendor:publish --provider="spiderwebtr\isauth\isAuthServiceProvider" --force --tag="public" --tag="config"

3- Edit config/isAuth.php

Under config folder, you'll see isAuth config file. Edit the fields for customizations.

return [
    "middleware"=>['web'], //for laravel routes (web,api...)
    "options"=>[
        "loginField"=>"email", //If your project uses username to login, change it with "username".
        "texts"=>[ //translate
            "placeholder"=>"Type Your Password",
            "wrong"=>"Wrong Password",
            "error"=>"Error",
            "button"=>"Login"
        ]
    ],
];

4- Include JQuery,Sweet Alert and @isAuthAssets in your footer

You can download the js files or just use cdn. @isAuthAssets will call isAuth.js and define auth object with your config.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
@isAuthAssets([
    "user"=>auth()->user(),
    "photo"=>$user->avatar //(not required) if you use avatar in your user system, pass the url of your user's avatar to "photo" key, if you don't use avatar, you can remove the key in array
])

Extras

:fire: isAuth function

isAuth function takes a callback parameter so in your code you can call isAuth to check the session before doing your js stuff.

auth.isAuth(function(){
    //do something 
});

Login modal will reveal if the session is dead. When you re-login, your code will work with callback.

Contributors

Feedback

If you give me some feedback I will be happy. You can show your satisfaction with star. :star:

Update Guide

  • v1.1 - If you downloaded the package in development version (dev-master), please remove it apply Installation Guide from this readme file (require,Create assets,Last Step).
  • v1.2 - Delete the js codes in footer, then start from step 2

More from the ecosystem

marcreichel/
laya-php
g4t.io
3 53

LayaPHP: Self-Hosted Text Classification for PHP and Laravel

Classify text in PHP without an LLM bill: typed decisions in 100+ languages, self-hosted. Laravel-ready SDK for Laya, a Jev AI alternative.

ai classification decision-engine
marcreichel/laya-php via Laravel News
Josh-Dovey/
postcodes-laravel
g4t.io
5 9

Postcodes for Laravel: GB Postcode Lookup and Geography Data

Postcodes for Laravel adds typed GB postcode lookups, validation, geography data, distance searches, and test fakes through the GB Postcodes API.

Josh-Dovey/postcodes-laravel via Laravel News
RedberryProducts/
mailbox-for-laravel
g4t.io
4 115

Mailbox for Laravel: Preview and Test Rendered Email

Mailbox for Laravel captures outgoing mail in a local dashboard and lets you test rendered HTML, recipients, and attachments with fluent assertions.

RedberryProducts/mailbox-for-laravel via Laravel News