Do you support a feature where I can revoke the se...
# support-questions-legacy
u
Do you support a feature where I can revoke the session for the user by checking a flag? When the user logs in I check for certain flags and don't create their session at all.
Copy code
Session.init({
    override: {
        functions: (originalImplementation) => {
            return {
                ...originalImplementation,
                createNewSession: async function (input) {
                    const userInfo = await ThirdPartyEmailPassword.getUserById(
                        input.userId
                    );
                    
                    const userProfile = getUserProfile(userInfo.id);
                    
                    if (!userProfile.disabledTemporarily) {
                        return originalImplementation.createNewSession(input);
                    }
                }
            }
        }
    }
})
r
hey @undesiredmonk if the flag is not set, you can return an empty session this way:
Copy code
ts
session = {
                getUserId: () => undefined,
                getJWTPayload: () => undefined,
                revoke: async () => undefined,
                updateJWTPayload: async () => undefined,
                getHandle: () => undefined,
                getAccessTokenLifeTimeMS: () => undefined,
                getRefreshTokenLifeTimeMS: () => undefined,
                getIDTokenLifeTimeMS: () => undefined,
                getAntiCsrfToken: () => undefined,
                getIDRefreshToken: () => undefined,
                updateAntiCsrfToken: async () => undefined,
                updateIDRefreshToken: async () => undefined,
                revokeAllSessionsForUser: async () => undefined,
                revokeMultipleSessions: async () => undefined,
                revokeSession: async () => undefined,
                createNewSession: async () => undefined,
            };
And this won't really create a session on the frontend.
u
I'm adding this logic in session recipe config. How can I do it
thirdPartySignInUpPOST
r
the session recipe config is the right place for this logic
cause the createNewSession function is called from the sign in / up APIs from the other recipe.
u
returning
undefined
from
createNewSession
throws
Type 'undefined' is not assignable to type 'SessionContainerInterface'
r
you don;t return undefined. Return an empty session object like i showed you above
the type of the above may not be 100% correct, but that TS will tell you anyway
In this link, if you scroll down a bit, you will see the code snippet for how an empty session can be returned: https://supertokens.com/docs/thirdpartyemailpassword/advanced-customizations/user-context#how-does-it-work
Copy code
ts
createNewSession: async function (input) {
                            if (input.userContext.isSignUp) {
                                /**
                                 * The execution will come here only in case
                                 * a sign up API is calling this function. This is because
                                 * only then will the input.userContext.isSignUp === true
                                 * (see above code).
                                 */
                                return {
                                    getAccessToken: () => "",
                                    getAccessTokenPayload: () => null,
                                    getExpiry: async () => -1,
                                    getHandle: () => "",
                                    getSessionData: async () => null,
                                    getTimeCreated: async () => -1,
                                    getUserId: () => "",
                                    revokeSession: async () => { },
                                    updateAccessTokenPayload: async () => { },
                                    updateSessionData: async () => { },
                                    mergeIntoAccessTokenPayload: async () => { },
                                    assertClaims: async () => { },
                                    fetchAndSetClaim: async () => { },
                                    getClaimValue: async () => undefined,
                                    setClaimValue: async () => { },
                                    removeClaim: async () => { },
                                }; // this is an empty session. It won't result in a session being created for the user.
                            }
                            return originalImplementation.createNewSession(input);
                        }
                    }
                }
            }
u
Thanks I'll try and get back to you.
3 Views