GithubHelp home page GithubHelp logo

Comments (5)

Pagebakers avatar Pagebakers commented on June 14, 2024

Have you enabled authentication on all your operations?

https://docs.wundergraph.com/docs/wundergraph-operations-ts-reference/configure-authentication

from wundergraph.

bart-sofomo avatar bart-sofomo commented on June 14, 2024

@Pagebakers obviously I did:

operations: {
    defaultConfig: {
      authentication: {
        required: true,
      },
    },

I think I know what is missing in the tutorial. Basically the NEXTJS_URL/api/wg/* is secured but when I directly call WUNDERGRAPH_URL/operations without the rewrite in NEXTJS -> that's when it's get tricky. When you do that you an put any kind of token like Beared xyz and wundergraph would still response because it is getting 200 and {} from /api/auth/session.

from wundergraph.

Pagebakers avatar Pagebakers commented on June 14, 2024

Thanks for the extra info. In that case the /api/auth/session response should throw an error in case the token is invalid. I'llr un some tests to verify this is broken.

from wundergraph.

Pagebakers avatar Pagebakers commented on June 14, 2024

I've tested it, and indeed requests are always accepted because the session endpoint doesn't throw an error when the session isn't valid.

You can create a new userInfo.ts handler in api/auth/userInfo.ts with the following code:

import { getToken } from 'next-auth/jwt';

export default async (req, res) => {
	// If you don't have NEXTAUTH_SECRET set, you will have to pass your secret as `secret` to `getToken`
	const token = await getToken({ req });
	if (token) {
		res.status(200);
		res.json({ name: token.name, email: token.email, picture: token.picture });
	} else {
		// Not Signed in
		res.status(401);
	}
	res.end();
};

And then update the userInfoEndpoint in wundergraph.config.ts to point to the userInfo handler instead.

This way you can also map nextauth user details to the wundergraph claims.

from wundergraph.

Pagebakers avatar Pagebakers commented on June 14, 2024

Docs have been updated, closing this for now.

from wundergraph.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.