mirror of
https://github.com/aykhans/slash-e.git
synced 2025-09-05 16:54:18 +00:00
refactor: migration auth api to v1
This commit is contained in:
@@ -3,7 +3,6 @@ package server
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/boojack/shortify/api"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
@@ -29,34 +28,10 @@ func hasPrefixes(src string, prefixes ...string) bool {
|
||||
|
||||
func defaultAPIRequestSkipper(c echo.Context) bool {
|
||||
path := c.Path()
|
||||
return hasPrefixes(path, "/api", "/o")
|
||||
return hasPrefixes(path, "/api")
|
||||
}
|
||||
|
||||
func (server *Server) defaultAuthSkipper(c echo.Context) bool {
|
||||
ctx := c.Request().Context()
|
||||
func (*Server) defaultAuthSkipper(c echo.Context) bool {
|
||||
path := c.Path()
|
||||
|
||||
// Skip auth.
|
||||
if hasPrefixes(path, "/api/auth") {
|
||||
return true
|
||||
}
|
||||
|
||||
// If there is openId in query string and related user is found, then skip auth.
|
||||
openID := c.QueryParam("openId")
|
||||
if openID != "" {
|
||||
userFind := &api.UserFind{
|
||||
OpenID: &openID,
|
||||
}
|
||||
user, err := server.Store.FindUser(ctx, userFind)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if user != nil {
|
||||
// Stores userID into context.
|
||||
c.Set(getUserIDContextKey(), user.ID)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
return hasPrefixes(path, "/api/v1/auth")
|
||||
}
|
||||
|
Reference in New Issue
Block a user