refac: reamaining auth surface rewrite, T0
This commit is contained in:
1 parent
6d510d2805
commit
aa865af2e9
50 files changed
+3723
-149
No files matched your search
@@ -7,3 +7,9 @@ const ArticleNotFoundErrorMessage = "Article not found"
|
||||
const ArticleTitleErrorMessage = "Article title must be between 3 and 200 characters."
|
||||
const RegistrationClosedErrorMessage = "You are not allowed to create a user. Log in or reset database."
|
||||
const RegistrationFailedErrorMessage = "Registration failed. Please try again later."
|
||||
const UnauthorizedErrorMessage = "You must be logged in to access this resource."
|
||||
const VerificationFailedErrorMessage = "The verification code is invalid or has expired."
|
||||
const AlreadyVerifiedErrorMessage = "This account is already verified and cannot be cancelled this way."
|
||||
const VerificationRequiredErrorMessage = "You must verify your account to access this resource."
|
||||
const PasswordResetRequestedMessage = "If an account exists for that email, a password reset link has been sent."
|
||||
const PasswordResetFailedErrorMessage = "The password reset code is invalid or has expired."
|
||||
@@ -0,0 +1,26 @@
|
||||
package claims
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/go-chi/jwtauth/v5"
|
||||
)
|
||||
|
||||
func UserId(r *http.Request) (uint32, bool) {
|
||||
_, claims, err := jwtauth.FromContext(r.Context())
|
||||
if err != nil {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
rawUserId, ok := claims["user_id"]
|
||||
if !ok {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
userIdFloat, ok := rawUserId.(float64)
|
||||
if !ok {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
return uint32(userIdFloat), true
|
||||
}
|
||||
Reference in new issue
Block a user