Skip to content

feat: implement refresh schema#373

Closed
Danielwinkelmann wants to merge 20 commits intosidebase:mainfrom
Danielwinkelmann:main
Closed

feat: implement refresh schema#373
Danielwinkelmann wants to merge 20 commits intosidebase:mainfrom
Danielwinkelmann:main

Conversation

@Danielwinkelmann
Copy link
Contributor

@Danielwinkelmann Danielwinkelmann commented May 9, 2023

Implement the local "refresh" schema, it's based on the local schema and extends it.

I used as much code and types as possible from the 'local' schema.

Types are always extended and not rewritten, to maximize the compatibility between the schemas.

Checklist:

  • manually checked my feature (created playground)
  • testing not applicable
  • screenshot not applicable

@BracketJohn
Copy link
Contributor

BracketJohn commented May 11, 2023

Thanks @Danielwinkelmann ❤️ 💯

This would be a great controbution, I will look into it in a bit (:

Note already: Tests are failing - can you check it out and resolve it?

@Danielwinkelmann
Copy link
Contributor Author

@BracketJohn I updated the lock file

CleanShot 2023-05-11 at 09 33 21@2x

@BracketJohn
Copy link
Contributor

Thanks - tests are still failing though, you can see why by clicking "Details: on the failing test. Here's the current state for convenience:
image

@Danielwinkelmann
Copy link
Contributor Author

@BracketJohn I can't figure out the problem.
The Linter have a problem with the '#imports' in the playground.
I never touched the auth-js playground.
If i remove everything in the playground he shows the same issue on the local playground and so on.

It must be an dependency problem.

Maybe we should disable the Listing Rule "import/namespace"

@BracketJohn
Copy link
Contributor

BracketJohn commented May 12, 2023

I figured it out! The problem is that you made extends of the root tsconfig an array which eslint-typescript cannot handle.

I:

  • fixed it,
  • added a CI for the refresh provider,
  • fixed a missing session-data from the main-merge I performed

I wanted to push the fix into your branch but don't have permissions on the fork. So for the time being here's the diff:

diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index ab2ac7c..94bff65 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -67,8 +67,6 @@ jobs:
       # start prod-app and curl from it
       - run: "timeout 60 pnpm start & (sleep 45 && curl --fail localhost:3000)"
 
-
-
   test-playground-authjs:
     runs-on: ubuntu-latest
     defaults:
@@ -99,3 +97,34 @@ jobs:
         env:
           AUTH_ORIGIN: 'http://localhost:3001'
           PORT: 3001
+
+  test-playground-refresh:
+    runs-on: ubuntu-latest
+    defaults:
+      run:
+        working-directory: ./playground-refresh
+    steps:
+      - uses: actions/checkout@v3
+
+      - name: Use Node.js 16.14.2
+        uses: actions/setup-node@v3
+        with:
+          node-version: 16.14.2
+
+      - uses: pnpm/action-setup@v2
+        name: Install pnpm
+        id: pnpm-install
+        with:
+          version: 8
+
+      # Install deps
+      - run: pnpm i
+
+      # Check building
+      - run: pnpm build
+
+      # start prod-app and curl from it
+      - run: "timeout 60 pnpm start & (sleep 45 && curl --fail localhost:$PORT)"
+        env:
+          AUTH_ORIGIN: 'http://localhost:3002'
+          PORT: 3002
diff --git a/src/module.ts b/src/module.ts
index 72983f3..314d3e4 100644
--- a/src/module.ts
+++ b/src/module.ts
@@ -60,7 +60,8 @@ const defaultsByBackend: { [key in SupportedAuthProviders]: DeepRequired<Extract
     refreshToken: {
       signInResponseRefreshTokenPointer: '/refreshToken',
       maxAgeInSeconds: 60 * 60 * 24 * 7 // 7 days
-    }
+    },
+    sessionDataType: { id: 'string | number' }
   },
   authjs: {
     type: 'authjs',
diff --git a/tsconfig.json b/tsconfig.json
index 92f65fd..2a7b6fa 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,6 +1,6 @@
 {
   // Note: we need to explicitly extend one of the playgrounds here in order to have a nice and working typecheckk, otherwise `nuxt`-types are going to be unknown
-  "extends": ["./playground-local/.nuxt/tsconfig.json", "./playground-refresh/.nuxt/tsconfig.json"],
+  "extends": "./playground-refresh/.nuxt/tsconfig.json",
   "exclude": ["../docs"],
   "include": ["src/"]
 }

@BracketJohn
Copy link
Contributor

Next problem:

image

This test basically checks whether the app launches and the / page is reachable without problems. Here it fails with a 403 for the refresh provider

Copy link
Contributor

@BracketJohn BracketJohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please also extends the docs for this feature?

You'd only need to focus on the v0.6 docs. There I remember at least the following places that need an update:

  • docs/content/v0.6/1.getting-started/1.index.md -> update the feature table
  • docs/content/v0.6/1.getting-started/3.quick-start.md -> add a refresh specific section (can also be very small if there's nothing special to consider)
  • docs/content/v0.6/2.configuration/2.nuxt-config.md -> add provider specific config options
  • docs/content/v0.6/3.application-side/2.session-access-and-management.md -> add provider specific section

If in some cases refresh behaves the same as local provicder you can of course keep the sections small and reference the local provider

@@ -0,0 +1,39 @@
import { _fetch } from '../../utils/fetch'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I have some points:

  • Do we need this plugin? Can we not rely on the server-side execution of the plugin.ts we already defined on the app to refresh the token on load?
  • The existance of this plugin forces the user to have a server, without it refresh could also work for fully-static apps. So if we keep this plugin (depends on the answer to my previous question) we should at least make it opt-in to ensure that static apps still work

name: 'refresh-token-plugin',
enforce: 'pre',
async setup (nuxtApp) {
// TODO: get rid of duplicate code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can resolve this now?

You could add helpers into the refresh/ composable folder and import them here - I guess it's mostly about pointer extraction?

If you want to go a bit further you could add a more generic pointer extraction helper that can be used here, in your useAuth composable and in the local useAuth composable

@zoey-kaiser
Copy link
Member

Hi @Danielwinkelmann 👋

I am going through some PRs and noticed yours is still open! Do you still want to continue with it or should we see that we take this over? 🤗

@dommi10
Copy link
Contributor

dommi10 commented Jul 31, 2023

Hi @zoey-kaiser can you create a beta based on this pull request please! this is very helpfull, litteraly what the package need to support local provider

@Danielwinkelmann
Copy link
Contributor Author

@zoey-kaiser Sorry for delay. Had a litte bit to much private stuff going on.
I will continue working on it this week.
The missing parts just documentation things and the (pre) server plugin.
@BracketJohn I thing we can let the server plugin exist, I will only need for SSR applications, to make sure to refresh the tokens, before making an api call from an other plugin

@zoey-kaiser
Copy link
Member

zoey-kaiser commented Jul 31, 2023

The missing parts just documentation things and the (pre) server plugin.

Sounds good! Ill get around to another review by Wednesday and then I can release a pre-version, so @dommi10 can test it!

@dommi10
Copy link
Contributor

dommi10 commented Jul 31, 2023

@zoey-kaiser i’m so excited to test

@zoey-kaiser zoey-kaiser changed the base branch from main to Danielwinkelmannimplement-refresh-schema August 2, 2023 13:54
@zoey-kaiser zoey-kaiser changed the base branch from Danielwinkelmannimplement-refresh-schema to main August 2, 2023 13:55
@zoey-kaiser
Copy link
Member

Hi @dommi10

I released a test version of this branch in a new package, as there is no documentation yet and there are still some kinks to iron out. However, I did want to let you have a look at it and see if everything works in your projects:

https://www.npmjs.com/package/sidebase-auth-refresh

Feedback is super appreciated, maybe you can find some issues or have some improvement tips! Once we merge this and finish the documentation you should be able to switch to the official package! This one is just for temporary testing.

@dommi10
Copy link
Contributor

dommi10 commented Aug 3, 2023

Hi @dommi10

I released a test version of this branch in a new package, as there is no documentation yet and there are still some kinks to iron out. However, I did want to let you have a look at it and see if everything works in your projects:

https://www.npmjs.com/package/sidebase-auth-refresh

Feedback is super appreciated, maybe you can find some issues or have some improvement tips! Once we merge this and finish the documentation you should be able to switch to the official package! This one is just for temporary testing.

Yes for sure

@dommi10
Copy link
Contributor

dommi10 commented Aug 3, 2023

Hi @dommi10

I released a test version of this branch in a new package, as there is no documentation yet and there are still some kinks to iron out. However, I did want to let you have a look at it and see if everything works in your projects:

https://www.npmjs.com/package/sidebase-auth-refresh

Feedback is super appreciated, maybe you can find some issues or have some improvement tips! Once we merge this and finish the documentation you should be able to switch to the official package! This one is just for temporary testing.

Still have an issue when you select refresh as provider, the entire app crash

@zoey-kaiser
Copy link
Member

Published a new test version:

https://www.npmjs.com/package/sidebase-auth-refresh

Should be available under 0.6.0-beta.5

@dommi10
Copy link
Contributor

dommi10 commented Aug 9, 2023

Published a new test version:

https://www.npmjs.com/package/sidebase-auth-refresh

Should be available under 0.6.0-beta.5

Let’s us test again

@zoey-kaiser
Copy link
Member

Let’s us test again

Let me know how it goes! If everything works well I want to aim to publish it properly next week!

@dommi10
Copy link
Contributor

dommi10 commented Aug 10, 2023

Published a new test version:

https://www.npmjs.com/package/sidebase-auth-refresh

Should be available under 0.6.0-beta.5

An issues on logout redirect and issus when you try to refresh the token it doesn't add AUTORIZATION HEADER

@dommi10
Copy link
Contributor

dommi10 commented Aug 10, 2023

An issues on logout redirect and issus when you try to refresh the token it doesn't add AUTORIZATION HEADER

An issues on logout redirect and issus when you try to refresh the token it doesn't add AUTORIZATION HEADER

@zoey-kaiser
Copy link
Member

zoey-kaiser commented Aug 10, 2023

An issues on logout redirect and issus when you try to refresh the token it doesn't add AUTORIZATION HEADER

Okay good to know! Thank you for the initial testing 💪
Would you be so kind to send over a reproduction to the repo where this occured? Then I can look into the source code here and make some suggestions 🤗

@dommi10
Copy link
Contributor

dommi10 commented Aug 10, 2023

An issues on logout redirect and issus when you try to refresh the token it doesn't add AUTORIZATION HEADER

Okay good to know! Thank you for the initial testing 💪 Would you be so kind to send over a reproduction to the repo where this occured? Then I can look into the source code here and make some suggestions 🤗

Screenshot 2023-08-10 143438

Error on Redirect after logout

Screenshot 2023-08-10 143124

No Autorization Header in refresh token request

@dommi10
Copy link
Contributor

dommi10 commented Aug 14, 2023

An issues on logout redirect and issus when you try to refresh the token it doesn't add AUTORIZATION HEADER

Okay good to know! Thank you for the initial testing 💪 Would you be so kind to send over a reproduction to the repo where this occured? Then I can look into the source code here and make some suggestions 🤗

Screenshot 2023-08-10 143438

Error on Redirect after logout

Screenshot 2023-08-10 143124

No Autorization Header in refresh token request

@zoey-kaiser !!

// TODO: get rid of duplicate code
const { rawToken, rawRefreshToken, refreshToken, lastRefreshedAt } = useAuthState()
if (refreshToken.value) {
const config = nuxtApp.$config.auth
Copy link

@MaxNvk MaxNvk Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that you forgot to put .public. level for the path. But actually, you can use useRuntimeConfig().public.auth like in the /src/runtime/plugin.ts for code consistency.

@clcoco
Copy link

clcoco commented Sep 25, 2023

Any update on this?

@akiot-b
Copy link

akiot-b commented Oct 23, 2023

I originally used nuxtjs/auth and the server side was running refresh token with express. is the sidebase/nuxt-auth refresh token going to work with third party servers such as express?

@dommi10
Copy link
Contributor

dommi10 commented Oct 24, 2023

I originally used nuxtjs/auth and the server side was running refresh token with express. is the sidebase/nuxt-auth refresh token going to work with third party servers such as express?

This specific version can answer our questions

@zoey-kaiser any updates please ?? another beta please based on new modifications made by @MaxNvk

@JeppePepp
Copy link

this would be amazing to get asap

dommi10 added a commit to dommi10/nuxt-auth that referenced this pull request Nov 21, 2023
fix bugs on reference of runtime config
add headers on refresh methode

Refs: sidebase#373
@zoey-kaiser
Copy link
Member

Taken over and merged in #581

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.

8 participants