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

Issue with User Role in Redis Authentication #3213

Closed
murtazabaanihali opened this issue Feb 10, 2025 · 1 comment
Closed

Issue with User Role in Redis Authentication #3213

murtazabaanihali opened this issue Feb 10, 2025 · 1 comment
Labels
bug Something isn't working fixed in dev Fixed in the dev branch

Comments

@murtazabaanihali
Copy link

Describe the Bug

Hello,

There is an issue when using Redis for user authentication. The problem is that only the user ID is being saved in the Redis database. Consequently, when the useAuth function in lib/middleware attempts to check if the user is an admin, it fails because the role property is missing.

Issue Description

In the useAuth function in lib/middleware, the user admin is being checked by the role property:

user.isAdmin = user.role === ROLES.admin;

However, when the user is authenticated using Redis, the role property is not present, leading to an incorrect admin status check.

Solution

To fix this issue, update the default export of src/pages/api/auth/login.ts. Currently, only the userId is saved in Redis:

if (redisEnabled) {
  const token = await saveAuth({ userId: user.id });
  return ok(res, { token, user });
}

Update this to include the role property as well:

if (redisEnabled) {
  const token = await saveAuth({ userId: user.id, role: user.role });
  return ok(res, { token, user });
}

This ensures that the role property is saved in Redis, allowing the useAuth function to accurately check the user's admin status.

Database

PostgreSQL

Relevant log output

Which Umami version are you using? (if relevant)

No response

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

@mikecao mikecao added bug Something isn't working fixed in dev Fixed in the dev branch labels Feb 11, 2025
@mikecao
Copy link
Collaborator

mikecao commented Feb 21, 2025

Fixed in v2.16.0.

@mikecao mikecao closed this as completed Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in dev Fixed in the dev branch
Projects
None yet
Development

No branches or pull requests

2 participants