Skip to content

Sohel Ahmed [Work in progress]

Authenticate Laravel app with user data stored in JSON file

PHP, Laravel, Authenticate, JSON, MySQL, Database1 min read

Authentication in Laravel app can also be done if all the user data in stored in JSON file and not in MySQL, PostgreSQL etc.

# Real World Use Case
# Versions, Links and References

Real World Use Case

Though it is very unlikely that this way of authentication will be used in any real world app, but this implementation can be used to implement custom auth provider which can use Redis, Lightweight Directory Access Protocol (LDAP) etc.

Still there might be some use cases:

  • If the users info are stored in separate DB and in case if it goes down, its exported backup file can be used here.

  • If initially the user info (in some cases) are only stored in excel sheet (or json file like here) and then it is required to authenticate the app on the top of that data, this might be helpful.

  • Using production data in locally running app: Production database have lot of records, and few of them are exported. That exported data can be used in locally running apps.

Versions, Links and References

Laravel: 5.5 (also relavant to versions till 7.X)

How to implement:

Official Laravel docs explains it amazingly.

https://laravel.com/docs/5.5/authentication#adding-custom-user-providers

Implementation repository - Data stored in JSON file: https://github.com/SOHELAHMED7/json_file_user_provider


Previous: Sorting calculated columns in Yii2

Next: Redis cache in NestJS

© 2020 by Sohel Ahmed [Work in progress]. All rights reserved.
Theme by LekoArts