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

Page role authentication does not work when using roles instead of role #4256

Open
mjyoung opened this issue Nov 22, 2023 · 7 comments
Open
Labels
kind/bug Something isn't working status/ready-to-work-on This issue is up for grabs

Comments

@mjyoung
Copy link

mjyoung commented Nov 22, 2023

What is the problem?

When creating a session and setting publicData.roles = ["Role1", "Role2"], using Page.authenticate = { role: "Role1" } does not work and will always result in an AuthenticationError.

It looks like this assumes we're always setting a single publicData.role instead of an array of roles:

!authorizeRole(authenticate.role, publicData.role as string)

Paste all your error logs here:

AuthenticationError

Paste all relevant code snippets here:

mutations/login.tsx

  await ctx.session.$create({ userId: user.id, roles: ["Role1", "Role2"] })

pages/protected.tsx

const Protected = () => {
  return <div>Hi</div>
}

export default Protected

Protected.authenticate = { role: ["Role1"] }

What are detailed steps to reproduce this?

  1. On login:
  await ctx.session.$create({ userId: user.id, roles: ["Role1", "Role2"] })
  1. Create pages/protected.tsx:
const Protected = () => {
  return <div>Hi</div>
}

export default Protected

Protected.authenticate = { role: ["Role1"] }
  1. Open browser and navigate to /protected

Will always get an error because the auth client only checks against the publicData.role instead of publicData.roles

Run blitz -v and paste the output here:

Blitz version: 2.0.0-beta.35 (global)
Blitz version: 2.0.0-beta.35 (local)
macOS Ventura | darwin-arm64 | Node: v20.8.1


 Package manager: pnpm

  System:
    OS: macOS 13.5.2
    CPU: (10) arm64 Apple M1 Pro
    Memory: 524.55 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.8.1 - ~/.asdf/installs/nodejs/20.8.1/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 10.1.0 - ~/.asdf/plugins/nodejs/shims/npm
  npmPackages:
    @blitzjs/auth: 2.0.0-beta.35 => 2.0.0-beta.35 
    @blitzjs/next: 2.0.0-beta.35 => 2.0.0-beta.35 
    @blitzjs/rpc: 2.0.0-beta.35 => 2.0.0-beta.35 
    @prisma/client: 5.4.2 => 5.4.2 
    blitz: 2.0.0-beta.35 => 2.0.0-beta.35 
    next: 13.5.4 => 13.5.4 
    prisma: 5.4.2 => 5.4.2 
    react: 18.2.0 => 18.2.0 
    react-dom: 18.2.0 => 18.2.0 
    typescript: ^4.8.4 => 4.9.5 

Please include below any other applicable logs and screenshots that show your problem:

No response

@mjyoung mjyoung added kind/bug Something isn't working status/triage labels Nov 22, 2023
@siddhsuresh siddhsuresh added the status/ready-to-work-on This issue is up for grabs label Nov 28, 2023
@siddhsuresh
Copy link
Member

thanks for the issue @mjyoung! It would be better to handle this case. Marking it as ready to work on.

@mjyoung
Copy link
Author

mjyoung commented Dec 29, 2023

Any update or ETA on this? :)

@mjyoung
Copy link
Author

mjyoung commented Jan 5, 2024

@siddhsuresh just another gentle ping on this. is this planned to be fixed in the near future?

@cmoileo
Copy link

cmoileo commented Jan 9, 2024

@mjyoung Hello ! If needed I can work on it :)

@siddhsuresh
Copy link
Member

that's great @cmoileo! It would be good to handle this. Let me know if I can help in any way.

@siddhsuresh just another gentle ping on this. is this planned to be fixed in the near future?

not planned per se, but I am ready to review the code for the fix if done by the community,

@cmoileo
Copy link

cmoileo commented Jan 10, 2024

@siddhsuresh Alright, I will work on it this week-end. I'll come to you if needed :)

@cmoileo
Copy link

cmoileo commented Jan 13, 2024

@siddhsuresh I've sent the PR -> #4275

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working status/ready-to-work-on This issue is up for grabs
Projects
None yet
Development

No branches or pull requests

4 participants