list all wallets for current user (WA-9)

This commit is contained in:
Fran Jurmanović
2021-05-29 21:50:48 +02:00
parent 9531cc14fb
commit 035ed4b486
7 changed files with 63 additions and 6 deletions

View File

@@ -1,7 +1,6 @@
package middleware
import (
"fmt"
"os"
"strings"
"wallet-api/pkg/models"
@@ -21,9 +20,11 @@ func Auth(c *gin.Context) {
}
token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
_, ok := token.Method.(*jwt.SigningMethodHMAC)
println(ok)
if !ok {
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
exceptionReturn.ErrorCode = "401001"
exceptionReturn.StatusCode = 401
exceptionReturn.Message = "Invalid token"
c.AbortWithStatusJSON(exceptionReturn.StatusCode, exceptionReturn)
}
return []byte(secret), nil
})

19
pkg/middleware/cors.go Normal file
View File

@@ -0,0 +1,19 @@
package middleware
import "github.com/gin-gonic/gin"
func CORSMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With")
c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS, GET, PUT")
if c.Request.Method == "OPTIONS" {
c.AbortWithStatus(204)
return
}
c.Next()
}
}