Archived
Template
1
0
This repository has been archived on 2023-12-20. You can view files and clone it, but cannot push or open issues or pull requests.
Files
golang-base-project/middleware/noauth.go

20 lines
361 B
Go
Raw Normal View History

2021-12-12 14:56:13 +01:00
package middleware
import (
"github.com/gin-gonic/gin"
"net/http"
)
// 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()
}
}