We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Here https://www.howtographql.com/graphql-go/8-logged-in-user-object/
mutation { createUser(input: {username: "user1", password: "123"}) }
Authorization
{ "Authorization": "" // use your own generated token }
mutation { createLink(input: {title: "real link!", address: "www.graphql.org"}){ user{ name } } }
{ "errors": [ { "message": "access denied", "path": [ "createLink" ] } ], "data": null }
The text was updated successfully, but these errors were encountered:
CreateLink function starts at
CreateLink
user := auth.ForContext(ctx) if user == nil { return &model.Link{}, fmt.Errorf("access denied") }
And the ForContext function is like this. I don't find anywhere fetching user information
ForContext
func ForContext(ctx context.Context) *users.User { raw, _ := ctx.Value(userCtxKey).(*users.User) return raw }
Sorry, something went wrong.
I got it fixed
git diff server.go diff --git a/server.go b/server.go index 1db5d8f..b29dd01 100644 --- a/server.go +++ b/server.go @@ -9,6 +9,7 @@ import ( "github.com/99designs/gqlgen/graphql/playground" graph "github.com/dove-young/hackernews/graph" "github.com/dove-young/hackernews/graph/generated" + "github.com/dove-young/hackernews/internal/auth" database "github.com/dove-young/hackernews/internal/pkg/db/mysql" "github.com/go-chi/chi" ) @@ -21,11 +22,12 @@ func main() { port = defaultPort } - router := chi.NewRouter() - database.InitDB() defer database.CloseDB() database.Migrate() + router := chi.NewRouter() + router.Use(auth.Middleware()) + server := handler.NewDefaultServer(generated.NewExecutableSchema(generated.Config{Resolvers: &graph.Resolver{}})) router.Handle("/", playground.Handler("GraphQL playground", "/query")) router.Handle("/query", server)
No branches or pull requests
Here https://www.howtographql.com/graphql-go/8-logged-in-user-object/
Authorization
JSONThe text was updated successfully, but these errors were encountered: