teldrive/routes/auth.go

35 lines
530 B
Go
Raw Normal View History

2023-08-12 19:21:42 +08:00
package routes
import (
"net/http"
"github.com/divyam234/teldrive-go/services"
"github.com/gin-gonic/gin"
)
func addAuthRoutes(rg *gin.RouterGroup) {
r := rg.Group("/auth")
authService := services.AuthService{SessionMaxAge: 30 * 24 * 60 * 60}
r.POST("/login", func(c *gin.Context) {
err := authService.SignIn(c)
if err != nil {
c.AbortWithError(err.Code, err.Error)
return
}
})
r.GET("/session", func(c *gin.Context) {
session := authService.GetSession(c)
c.JSON(http.StatusOK, session)
})
}