@@ -69,13 +69,17 @@ export default class SuperTokensNextjsSSRAPIWrapper {
6969 * @param cookies - The cookies store exposed by next/headers (await cookies())
7070 * @returns The session context value or directly redirects the user to either the login page or the refresh API
7171 **/
72- static async getServerComponentSessionWithoutClaims ( cookies : CookiesStore ) : Promise < SSRSessionContext > {
72+ static async getServerComponentSessionWithoutClaimValidation (
73+ cookies : CookiesStore ,
74+ requireAuth : boolean = false
75+ ) : Promise < SSRSessionContext > {
7376 const redirectPath = cookies . get ( CURRENT_PATH_COOKIE_NAME ) ?. value || "/" ;
7477 const authPagePath = getAuthPagePath ( redirectPath ) ;
7578 const refreshLocation = getRefreshLocation ( redirectPath ) ;
7679
7780 const { state, session } = await getSSRSessionState ( cookies ) ;
7881 logDebugMessage ( `SSR Session State: ${ state } ` ) ;
82+
7983 switch ( state ) {
8084 case "front-token-not-found" :
8185 case "front-token-invalid" :
@@ -86,7 +90,8 @@ export default class SuperTokensNextjsSSRAPIWrapper {
8690 case "access-token-not-found" :
8791 case "tokens-do-not-match" :
8892 logDebugMessage ( `Redirecting to refresh API: ${ refreshLocation } ` ) ;
89- return redirect ( refreshLocation ) ;
93+ const redirectPath = requireAuth ? authPagePath : refreshLocation ;
94+ return redirect ( redirectPath ) ;
9095 case "tokens-match" :
9196 logDebugMessage ( "Returning session object" ) ;
9297 return session as SSRSessionContext ;
@@ -104,9 +109,8 @@ export default class SuperTokensNextjsSSRAPIWrapper {
104109 * @returns An object that includes session context value and the status of the session ('valid' | 'expired' | 'invalid')
105110 * If the status is 'invalid' or 'expired' then the users should be considered as unauthenticated
106111 **/
107- static async getServerActionSessionWithoutClaims (
108- cookies : CookiesStore ,
109- requireAuth : boolean = false
112+ static async getServerActionSessionWithoutClaimValidation (
113+ cookies : CookiesStore
110114 ) : Promise <
111115 { session : SSRSessionContext ; status : "valid" } | { status : "expired" | "invalid" ; session : undefined }
112116 > {
@@ -116,12 +120,6 @@ export default class SuperTokensNextjsSSRAPIWrapper {
116120 return { session : session as SSRSessionContext , status : "valid" } ;
117121 }
118122
119- if ( requireAuth ) {
120- const redirectPath = cookies . get ( CURRENT_PATH_COOKIE_NAME ) ?. value || "/" ;
121- const authPagePath = getAuthPagePath ( redirectPath ) ;
122- return redirect ( authPagePath ) ;
123- }
124-
125123 if ( [ "tokens-do-not-match" , "front-token-expired" , "access-token-not-found" ] . includes ( state ) ) {
126124 return { status : "expired" , session : undefined } ;
127125 }
@@ -169,7 +167,7 @@ export default class SuperTokensNextjsSSRAPIWrapper {
169167 * @param request - The request object available inside getServerSideProps ctx (ctx.req)
170168 * @returns The session context value or a redirects path to send the user to the refresh API or the login page
171169 **/
172- static async getServerSidePropsSessionWithoutClaims (
170+ static async getServerSidePropsSessionWithoutClaimValidation (
173171 request : Request & { cookies : CookiesObject }
174172 ) : Promise < GetServerSidePropsReturnValue > {
175173 const appInfo = SuperTokensNextjsSSRAPIWrapper . getConfigOrThrow ( ) . appInfo ;
@@ -203,11 +201,12 @@ export default class SuperTokensNextjsSSRAPIWrapper {
203201}
204202
205203export const init = SuperTokensNextjsSSRAPIWrapper . init ;
206- export const getServerComponentSessionWithoutClaims =
207- SuperTokensNextjsSSRAPIWrapper . getServerComponentSessionWithoutClaims ;
208- export const getServerActionSessionWithoutClaims = SuperTokensNextjsSSRAPIWrapper . getServerActionSessionWithoutClaims ;
209- export const getServerSidePropsSessionWithoutClaims =
210- SuperTokensNextjsSSRAPIWrapper . getServerSidePropsSessionWithoutClaims ;
204+ export const getServerComponentSessionWithoutClaimValidation =
205+ SuperTokensNextjsSSRAPIWrapper . getServerComponentSessionWithoutClaimValidation ;
206+ export const getServerActionSessionWithoutClaimValidation =
207+ SuperTokensNextjsSSRAPIWrapper . getServerActionSessionWithoutClaimValidation ;
208+ export const getServerSidePropsSessionWithoutClaimValidation =
209+ SuperTokensNextjsSSRAPIWrapper . getServerSidePropsSessionWithoutClaimValidation ;
211210export const ensureSessionAndCall = SuperTokensNextjsSSRAPIWrapper . ensureSessionAndCall ;
212211
213212function getAuthPagePath ( redirectPath : string ) : string {
0 commit comments