-
Notifications
You must be signed in to change notification settings - Fork 88
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: SessionAuth SSR support (initialSessionAuthContext) #789
feat: SessionAuth SSR support (initialSessionAuthContext) #789
Conversation
@@ -13,6 +13,7 @@ | |||
* under the License. | |||
*/ | |||
"use strict"; | |||
"use client"; // Important for NextJS support (SessionAuth is a client component) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can't do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should create a separate file /recipe/session/clientcomponents/sessionauth.js
@@ -57,6 +57,7 @@ describe("ThirdPartyPasswordless.SignInAndUp", () => { | |||
}); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to add an e2e test that uses SessionAuth without calling the init function and make sure that it works (in the context of SSR)
@@ -155,6 +156,34 @@ describe("SessionAuth", () => { | |||
|
|||
result.unmount(); | |||
}); | |||
|
|||
test("set initial SSR context (initialSessionAuthContext)", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add some more tests please
const initialContext: SessionContextType = props.initialSessionAuthContext | ||
? { | ||
...props.initialSessionAuthContext, | ||
invalidClaims: [], // invalidClaims is currently unsupported on server (SSR) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
invalidClaims: [], // invalidClaims is currently unsupported on server (SSR) | |
invalidClaims: [], // invalidClaims is currently unsupported on server (SSR), | |
isContextFromSSR: true, |
f99aef2
into
supertokens:sessionauth-ssr
Summary of change
Adds
initialSessionAuthContext
support forSessionAuth
component.initialSessionAuthContext
is an initial state that Session provider uses to create a context.initialSessionAuthContext
property toSessionAuthProps
isContextFromSSR
toLoadedSessionContext
that signals if a session context is provided from a server or computed on the client.isContextFromSSR: true
when uses initial context preloaded from server (SSR). This meansinvalidClaims[]
andaccessDeniedValidatorError
are not yet evaluated and the client should not trust the data (as discussed with @porcellus )isContextFromSSR: false
when uses a client generated context (ex: after client rerender)Related issues
Test Plan
Tested locally on a NextJS implementation using supertokens. Tested scenarios include:
<SessionAuth />
rendering with children that consume context (userId) -> Renders on server side, no flash or hydration issuesrequireAuth: false
on server component. -><SessionAuth />
provides an empty session context and renders childrenDocumentation changes
TODO.
(If relevant, please create a PR in our docs repo, or create a checklist here highlighting the necessary changes)
Checklist for important updates
frontendDriverInterfaceSupported.json
file has been updated (if needed)package.json
package-lock.json
lib/ts/version.ts
npm run build-pretty
git tag
) in the formatvX.Y.Z
, and then find the latest branch (git branch --all
) whoseX.Y
is greater than the latest released tag.someFunc: function () {..}
).size-limit
section ofpackage.json
with the size limit set to the current size rounded up.rollup.config.mjs
Remaining TODOs for this PR
getInitialSessionAuthContext
support tosupertokens-node