- Add avatar upload functionality with public URL access. - Implement user login with email and password authentication. - Create endpoints for fetching and updating the authenticated user's profile. - Set up database migrations for user profiles, including email and role management. - Introduce personal data management linked to user profiles. - Add email verification process with welcome email templates.
24 lines
722 B
Go
24 lines
722 B
Go
package admin
|
|
|
|
import (
|
|
authsvc "encore.app/auth"
|
|
"encore.dev/beta/auth"
|
|
"encore.dev/beta/errs"
|
|
"encore.dev/middleware"
|
|
)
|
|
|
|
// RequireAdmin ensures the caller is logged in and has the admin role
|
|
// before any endpoint in this service runs.
|
|
//
|
|
//encore:middleware target=all
|
|
func RequireAdmin(req middleware.Request, next middleware.Next) middleware.Response {
|
|
if _, ok := auth.UserID(); !ok {
|
|
return middleware.Response{Err: &errs.Error{Code: errs.Unauthenticated, Message: "must be logged in"}}
|
|
}
|
|
data, _ := auth.Data().(*authsvc.AuthData)
|
|
if data == nil || !data.Role.IsAdmin() {
|
|
return middleware.Response{Err: &errs.Error{Code: errs.PermissionDenied, Message: "admin role required"}}
|
|
}
|
|
return next(req)
|
|
}
|