-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from grant-baer/login-with-jwt
Login with jwt
- Loading branch information
Showing
4 changed files
with
57 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// auth.js (utility file) | ||
|
||
// Import the required libraries | ||
import jwt from 'jsonwebtoken'; | ||
|
||
// Secret key used to sign the JWT tokens (should match the key used in your backend) | ||
const JWT_SECRET = 'CHANGE_TO_SECURE_KEY'; | ||
|
||
// Function to check if the user is authenticated based on the JWT token | ||
export function isAuthenticated(token) { | ||
try { | ||
// Verify and decode the JWT token | ||
const decodedToken = jwt.verify(token, JWT_SECRET); | ||
|
||
// If the verification is successful, the user is authenticated | ||
return true; | ||
} catch (error) { | ||
// If there's an error, such as an expired or invalid token, the user is not authenticated | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters