Skip to content

AdnanTech

Programming tutorials

Menu
  • Python
  • PHP
    • Laravel
    • WordPress
  • Javascript
    • React JS
    • Node.js
    • Vue JS
  • Databases
    • MySQL
    • MongoDB
  • Mobile apps
    • Android
    • iOS
  • Tutorials
    • Ticketing system
    • Chat app
  • Blog
  • Projects
  • API
    • Social network API
  • Services
    • Hash Generator
    • World Clock
    • Word Counter
    • Currency Converter
    • Financial Ledger
    • Time Difference
    • Stopwatch & Timer
    • Google Maps
  • SAAS
    • Job Entry

Authentication

by adnanafzal565Posted onOctober 6, 2024October 6, 2024

Following steps are included in the authentication process:

  • Register
  • Verify email (if required)
  • Login
  • Get authenticated user
  • Save profile
  • Change password
  • Logout
  • Send password reset link
  • Reset password

Register

This API allows you to register a new user to the social network. It will return an error if the email already exists in the database. If the email verification is enabled from admin panel, then it will also sends an email to the provided email address to verify the email.

URL = http://localhost:8000/api/register

Method = POST

Headers

Acceptapplication/json

Parameters

KeyTypeRequired
namestringYes
emailstringYes
passwordstringYes

Response

Status = 200

{
    "status": "success",
    "message": "Account has been created. Please login now.",
    "verification": true
}
  • If “verification” is true, then the verify-email API is required in the next step.
  • If “verification” is false, goto login API.

Verify email

Verfies the user email if the “verification” from register API is true. Otherwise, you can skip this step.

URL = http://localhost:8000/api/verify-email

Method = POST

Headers

Acceptapplication/json

Parameters

KeyTypeRequired
emailstringYes
codestringYes
  • code: The email verification code you have recieved in your inbox.

Response

Status = 200

{
    "status": "success",
    "message": "Account has been verified. You can login now."
}

Login

Authenticates the user using his email and password. If the email verification is allowed and the user has not yet verifies his email, then it will return an error.

URL = http://localhost:8000/api/login

Method = POST

Headers

Acceptapplication/json

Parameters

KeyTypeRequired
emailstringYes
passwordstringYes

Response

Status = 200

{
    "status": "success",
    "message": "Login successfully.",
    "access_token": "4|aPee2JhDXFizoHLS0D7Ye6h7K3y3pRNnaG7HZvxd3f1ba673"
}
  • Save “access_token” in your client application’s local storage. This will be used in headers of other APIs where authentication is required.

Get authenticated user

Return the authenticated user if logged-in. Otherwise, it will return status code = 401 Unuthorized. It will also return the number of unread messages user has. You will more about messages in Messages API section.

URL = http://localhost:8000/api/me

Method = POST

Headers

Acceptapplication/json
AuthorizationBearer {access_token}

Response

Status = 200

{
    "status": "success",
    "message": "Data has been fetched.",
    "user": {
        "id": 2,
        "name": "Adnan Afzal",
        "email": "support@adnan-tech.com",
        "profile_image": "http://localhost:8000/storage/users/2/profile-1727853217-IMG_0025.JPG"
    },
    "new_messages": 0
}
  • new_messages: Number of unread messages this user has. More on this in Message API section.

Save profile

Saves the user profile name and image (if provided). If user has provided a profile image, then it will delete the previous profile image of that user.

URL = http://localhost:8000/api/save-profile

Method = POST

Headers

Acceptapplication/json
AuthorizationBearer {access_token}

Parameters

KeyTypeRequired
emailstringYes
profile_imagefile (image only)No

Response

Status = 200

{
    "status": "success",
    "message": "Profile has been saved."
}

Change password

Changes the password of the authenticated user. User must provide the current and the new password. It will first check if the current password is correct. If it is correct, then it will update the password. Otherwise, it will return an error.

URL = http://localhost:8000/api/change-password

Method = POST

Headers

Acceptapplication/json
AuthorizationBearer {access_token}

Parameters

KeyTypeRequired
current_passwordstringYes
new_passwordstringYes

Response

Status = 200

{
    "status": "success",
    "message": "Password has been changed."
}

Logout

Logs out the current user. Basically, it deletes the user access token from database. It is recommended to remove the access token from local storage too from client application.

URL = http://localhost:8000/api/logout

Method = POST

Headers

Acceptapplication/json
AuthorizationBearer {access_token}

Response

Status = 200

{
    "status": "success",
    "message": "User has been logged-out."
}

Send password reset link

If you forgot your password, you can call this API to email you instructions to reset your password. Make sure you have set SMTP configurations from admin panel in order to send the email.

URL = http://localhost:8000/api/send-password-reset-link

Method = POST

Headers

Acceptapplication/json

Parameters

KeyTypeRequired
emailstringYes

Response

Status = 200

{
    "status": "success",
    "message": "Instructions to reset password has been sent."
}

Reset password

After clicking the link from email from previous step, you can call this API to reset your password. You need to provide your email and token you have received in your email. The token will be attached in the URL and will not be visible in the email. Then you must enter your password 2 times to reset it.

URL = http://localhost:8000/api/reset-password

Method = POST

Headers

Acceptapplication/json

Parameters

KeyTypeRequired
emailstringYes
tokenstringYes
passwordstringYes
password_confirmationstringYes (must be same as password)
  • token: This is the string passed in the email when you request to send a password reset link in the previous step.

Response

Status = 200

{
    "status": "success",
    "message": "Password has been reset."
}

Published by adnanafzal565

View all posts by adnanafzal565

Post navigation

Prev Installation
Next Friends

Recent Posts

  • SAAS in React + Laravel – Job Entry
  • Show selected images from input type file – React
  • Add dynamic rows in React
  • Soft Delete 🗑 – Node.js, MongoDB
  • 2 ways to loop through a number in React

Recent Comments

  1. canada pharmaceuticals online generic on PDF view in browser and export as file – PHP
  2. System on (no title)
  3. adnanafzal565 on (no title)
  4. adnanafzal565 on (no title)
  5. System on (no title)

Archives

  • May 2025
  • March 2025
  • February 2025
  • January 2025
  • November 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • November 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020

Categories

  • Android
  • Complete Projects
  • CSS
  • FFmpeg
  • Git
  • htaccess
  • HTML
  • iOS
  • Javascript
  • Laravel
  • Leap Motion Controller
  • MEVN
  • MongoDB
  • MySQL
  • Node.js
  • PHP
  • Python
  • React JS
  • Swift
  • Tips & Tricks
  • Uncategorized
  • Vue JS
  • WordPress
AdnanTech © All rights reserved. 2013 - 2025