add logout
This commit is contained in:
1
main.go
1
main.go
@@ -50,6 +50,7 @@ func main() {
|
||||
|
||||
// Users
|
||||
mainGroup.POST("/auth/login", users.Login)
|
||||
mainGroup.POST("/auth/logout", users.Logout)
|
||||
mainGroup.GET("/users/me", users.GetCurrentUser)
|
||||
mainGroup.GET("/users", users.GetUsers)
|
||||
mainGroup.GET("/users/:id", users.GetUsers)
|
||||
|
||||
@@ -43,18 +43,25 @@ func Login(c echo.Context) (err error) {
|
||||
}
|
||||
|
||||
c.SetCookie(&http.Cookie{
|
||||
Name: "accessToken",
|
||||
Value: _token,
|
||||
Path: "/",
|
||||
MaxAge: 31536000,
|
||||
Expires: time.Now().Add(24 * time.Hour),
|
||||
Secure: true,
|
||||
SameSite: 4,
|
||||
Name: "accessToken",
|
||||
Value: _token,
|
||||
Path: "/",
|
||||
Expires: time.Now().Add(24 * time.Hour),
|
||||
})
|
||||
|
||||
return c.JSON(http.StatusOK, u)
|
||||
}
|
||||
|
||||
func Logout(c echo.Context) error {
|
||||
c.SetCookie(&http.Cookie{
|
||||
Name: "accessToken",
|
||||
Value: "",
|
||||
Path: "/",
|
||||
Expires: time.Unix(0, 0),
|
||||
})
|
||||
return c.NoContent(http.StatusOK)
|
||||
}
|
||||
|
||||
func GetCurrentUser(c echo.Context) error {
|
||||
data, err, _ := api.GetRequest(config.Env.MSHosts.UsersHost+"/me", c.Request().Header)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user