Skip to content
New issue

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

Incorrect authentication error message #39

Closed
minhdtb opened this issue Jun 13, 2022 · 2 comments
Closed

Incorrect authentication error message #39

minhdtb opened this issue Jun 13, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@minhdtb
Copy link

minhdtb commented Jun 13, 2022

Bug description

incorrect authentication error when RBAC is not sufficient

How to reproduce

Create a simple WunderGraph application from template and use open id connect auth provider

Operation

query @rbac(requireMatchAll: [tester,admin]) {
    findUsers: db_findManyuser {
        id
        email
        name
    }
}

create a hook in wundergraph.server.ts

export default configureWunderGraphServer<HooksConfig, InternalClient>((serverContext) => ({
    hooks: {
        authentication: {
            mutatingPostAuthentication: async (user) => {
                return {
                    status: "ok",
                    user: {
                        ...user,
                        roles: [
                            "tester",
                        ]
                    }
                }
            }
        },
        queries: {},
        mutations: {},
    },
    graphqlServers: [],
}));

index.tsx

import { NextPage } from 'next';
import styles from '../styles/Home.module.css';
import { AuthProviders, useQuery, useWunderGraph, withWunderGraph } from '../components/generated/nextjs';

const Home: NextPage = () => {
    const {result: test} = useQuery.Test();
    const {user, login, logout} = useWunderGraph();
    return (
        <div className={styles.container}>
            <button onClick={() => login(AuthProviders.storeo)}>Login</button>
            <button onClick={() => logout({
                logout_openid_connect_provider: true
            })}>Logout
            </button>
            <h1 className={styles.title}>Hello WunderGraph! {user?.user_id}</h1>
            {test.status === "ok" && test.data.findUsers.length !== 0 && (
                <div>
                    {test.data.findUsers.map(message => {
                        return (<div key={message.id}>
                            <p>
                                id: {message.id}, email: {message.email}, name: {message.name}
                            </p>
                        </div>)
                    })}
                </div>
            )}
            {test.status === "error" && (
                <div>
                    {test.errors.map(value => {
                        return (<div key={value.message}>
                            <p>
                               message: {value.message}, path: {value.path}
                            </p>

                        </div>)
                    })}
                </div>
            )}
        </div>
    );
};

export default withWunderGraph(Home);

Actual error message:

Unexpected token u in JSON at position 0

Expected behavior

The error message should be Access denied or something related to exact problem

WunderGraph information

Environment & setup

  • OS: Ubuntu
  • Go version: go1.17.2 linux/amd64
  • Database: PostgreSQL
  • Node.js version: v16.15.1

WunderCtl Version

Version: 0.90.32
Commit: 386a3d4b66204411dc89da6919aad0bebe524657
Date: 2022-06-06T12:21:43Z
BuiltBy: ci

@minhdtb minhdtb added the bug Something isn't working label Jun 13, 2022
@jensneuse
Copy link
Member

Your observation is correct, this needs fixing. Putting it on the backlog.

@jensneuse
Copy link
Member

Fixed with @wundergraph/nextjs@0.0.28

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants