1
0
mirror of https://github.com/Uttkarsh-raj/Plannerly.git synced 2025-11-23 21:54:39 +02:00

initial commit

This commit is contained in:
Uttkarsh-raj
2023-10-25 20:17:27 +05:30
commit 8f497c1610
11 changed files with 563 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
package middleware
import (
"fmt"
"net/http"
"github.com/Uttkarsh-raj/To_Do_App/helpers"
"github.com/gin-gonic/gin"
)
func Authentication() gin.HandlerFunc {
return func(ctx *gin.Context) {
clientToken := ctx.Request.Header.Get("token")
if clientToken == "" {
ctx.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Sprintf("No Authorization header provided.")})
ctx.Abort()
return
}
claims, err := helpers.ValidateToken(clientToken)
if err != "" {
ctx.JSON(http.StatusInternalServerError, gin.H{"error": err})
ctx.Abort()
return
}
ctx.Set("email", claims.Email)
ctx.Set("first_name", claims.First_name)
ctx.Set("last_name", claims.Last_name)
ctx.Set("uid", claims.Uid)
ctx.Next()
}
}