You've already forked golang-base-project
Initial commit
This commit is contained in:
21
middleware/noauth.go
Normal file
21
middleware/noauth.go
Normal file
@ -0,0 +1,21 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var SessionIdentifierKey = "SESSION_IDENTIFIER"
|
||||
|
||||
// NoAuth is for routes that can only be accessed when the user is unauthenticated
|
||||
func NoAuth() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
_, exists := c.Get(UserIDKey)
|
||||
if !exists {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
c.Redirect(http.StatusTemporaryRedirect, "/admin")
|
||||
c.Abort()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user