41 lines
879 B
Go
41 lines
879 B
Go
package auth
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"gitea.konchin.com/ytshih/inp2025/game/models"
|
|
"gitea.konchin.com/ytshih/inp2025/game/server/middlewares"
|
|
"gitea.konchin.com/ytshih/inp2025/game/types"
|
|
"gitea.konchin.com/ytshih/inp2025/game/utils"
|
|
"github.com/uptrace/bunrouter"
|
|
)
|
|
|
|
// PostLogout
|
|
//
|
|
// @Success 200
|
|
// @Router /auth/logout [post]
|
|
func (self *Handlers) PostLogout(
|
|
w http.ResponseWriter,
|
|
req bunrouter.Request,
|
|
) error {
|
|
ctx := req.Context()
|
|
|
|
user, ok := ctx.Value(types.User("")).(models.User)
|
|
if !ok {
|
|
return middlewares.HTTPError{
|
|
StatusCode: http.StatusBadRequest,
|
|
Message: "missing user",
|
|
}
|
|
}
|
|
|
|
if err := self.db.DeleteUserStatus(ctx, user.Username); err != nil {
|
|
return middlewares.HTTPError{
|
|
StatusCode: http.StatusInternalServerError,
|
|
Message: "failed to delete user status",
|
|
OriginError: err,
|
|
}
|
|
}
|
|
|
|
return utils.Success(w)
|
|
}
|