aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/graphql/resolver/auth_helpers.go
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-11-02 00:00:35 +0900
committernsfisis <nsfisis@gmail.com>2025-11-02 00:00:35 +0900
commit104341ddc4add57f83c58cb3fabb23b6fbfdd3e4 (patch)
tree862b109fe257e6170a88929729dae3bddfb6eb49 /backend/graphql/resolver/auth_helpers.go
parentba1e0c904f810193f25d4f88cc2bb168f1d625fe (diff)
downloadfeedaka-104341ddc4add57f83c58cb3fabb23b6fbfdd3e4.tar.gz
feedaka-104341ddc4add57f83c58cb3fabb23b6fbfdd3e4.tar.zst
feedaka-104341ddc4add57f83c58cb3fabb23b6fbfdd3e4.zip
Diffstat (limited to 'backend/graphql/resolver/auth_helpers.go')
-rw-r--r--backend/graphql/resolver/auth_helpers.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/backend/graphql/resolver/auth_helpers.go b/backend/graphql/resolver/auth_helpers.go
new file mode 100644
index 0000000..433e9e9
--- /dev/null
+++ b/backend/graphql/resolver/auth_helpers.go
@@ -0,0 +1,35 @@
+package resolver
+
+import (
+ "context"
+ "errors"
+ "fmt"
+
+ "github.com/labstack/echo/v4"
+ "golang.org/x/crypto/bcrypt"
+ appcontext "undef.ninja/x/feedaka/context"
+)
+
+// getUserIDFromContext retrieves the authenticated user ID from context
+// This is a wrapper around the GetUserID function from the context package
+func getUserIDFromContext(ctx context.Context) (int64, error) {
+ userID, ok := appcontext.GetUserID(ctx)
+ if !ok {
+ return 0, fmt.Errorf("authentication required")
+ }
+ return userID, nil
+}
+
+// Helper function to get Echo context from GraphQL context
+func getEchoContext(ctx context.Context) (echo.Context, error) {
+ echoCtx, ok := ctx.Value("echo").(echo.Context)
+ if !ok {
+ return nil, errors.New("echo context not found")
+ }
+ return echoCtx, nil
+}
+
+func verifyPassword(hashedPassword, password string) bool {
+ err := bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(password))
+ return err == nil
+}