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

Unable to update the session using newly minted JWT token #1263

Open
2 tasks done
anshul-kai opened this issue Aug 29, 2024 · 0 comments
Open
2 tasks done

Unable to update the session using newly minted JWT token #1263

anshul-kai opened this issue Aug 29, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@anshul-kai
Copy link

anshul-kai commented Aug 29, 2024

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

Although the JWT secret is exposed via the dashboard, one is unable to make use of it to update the session using the supabase.auth.setSession function. It ignores the changes made to the newly created & signed tokens.

What is the purpose of exposing the JWT secret if user-created tokens are being ignored?

To Reproduce

  import { createServerClient } from '@supabase/ssr';
  import { headers, cookies } from 'next/headers';

  const supabase = createServerClient(
    process.env.NEXT_PUBLIC_SUPABASE_URL!,
    process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
    {
      cookies: {
        getAll() {
          return cookieStore.getAll();
        },
        setAll(cookiesToSet) {
          try {
            cookiesToSet.forEach(({ name, value, options }) => {
              cookieStore.set(name, value, options);
            });
          } catch (error) {
          }
        }
      }
    }
  );

  const {
    data: { session }
  } = await supabase.auth.getSession();

  const decoded = jwt.verify(
    session.access_token,
    process.env.SUPABASE_JWT_SECRET!
  );

  // Update expiry to 1 minute from now
  const newTokenJson = { ...decoded, exp: Math.round(Date.now() / 1000 + 60) };
  const newToken = jwt.sign(newTokenJson, process.env.SUPABASE_JWT_SECRET!);

  // No error is returned and the data object reflects the new token but auth.sessions table is not updated. A call to auth.getSession() continues to return the old values.
  const { data, error } = await supabase.auth.setSession({
    access_token: newToken,
    refresh_token: 'abc'
  });

Expected behavior

Create APIs/functions to override default token functionality ie. set expiration and renewal rules

  1. One should be able to update/override the expiration of the current JWT token
  2. One should be able to disable or intercept the auto-refresh functionality

System information

  • OS: macOS
  • Platform: Next.js
  • Browser: Chrome
  • Version of supabase-js: 2.45.2
  • Version of supabase-ssr: 0.5.1
  • Version of Node.js: 20.12.2
@anshul-kai anshul-kai added the bug Something isn't working label Aug 29, 2024
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

1 participant