mirror of
https://github.com/pushbits/server.git
synced 2025-04-29 10:16:50 +02:00
32 lines
898 B
Go
32 lines
898 B
Go
package authentication
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
|
|
"github.com/pushbits/server/internal/model"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// GetApplication returns the application which was previously registered by the authentication middleware.
|
|
func GetApplication(ctx *gin.Context) *model.Application {
|
|
app, ok := ctx.MustGet("app").(*model.Application)
|
|
if app == nil || !ok {
|
|
ctx.AbortWithError(http.StatusInternalServerError, errors.New("an error occured while retrieving application from context"))
|
|
return nil
|
|
}
|
|
|
|
return app
|
|
}
|
|
|
|
// GetUser returns the user which was previously registered by the authentication middleware.
|
|
func GetUser(ctx *gin.Context) *model.User {
|
|
user, ok := ctx.MustGet("user").(*model.User)
|
|
if user == nil || !ok {
|
|
ctx.AbortWithError(http.StatusInternalServerError, errors.New("an error occured while retrieving user from context"))
|
|
return nil
|
|
}
|
|
|
|
return user
|
|
}
|