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

feat: save provider access/refresh tokens in cookies #197

Merged
merged 1 commit into from Jul 3, 2023

Conversation

mitjans
Copy link
Contributor

@mitjans mitjans commented Jun 15, 2023

Store provider access/refresh tokens in cookies

This PR stores provider access/refresh tokens in cookies, to allow server routes to use provider APIs.

Types of changes

  • New feature (a non-breaking change which adds functionality)

Description

When logging in users with external API scopes for a provider (for example, Github), the application will need access to the provider token to access the provider's API. This token is stored in the session object, which is only stored in the client (if I'm not mistaken).

When calling an API in my project, only sb-access-token and sb-refresh-token cookies are sent, which means that if I want to access Github's API from a server route, I won't be able to do so.

As I see it, there are 2 workarounds for this:

  1. Store provider's access/refresh tokens in a Supabse table and access that table from server (vanilla, and cumbersome)
  2. Store provider's access/refresh tokens in a cookie, so that the server has direct access if needed.

This PR implements the second solution. To access the provider's token from the server, one can simply:

export default defineEventHandler((event) => {
  const providerToken = getCookie(event, 'sb-provider-token');

  ...
});

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes (if not applicable, please state why)

@netlify
Copy link

netlify bot commented Jun 15, 2023

👷 Deploy request for n3-supabase pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit eac40fa

@larbish larbish merged commit ea8c21f into nuxt-modules:main Jul 3, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants