In `supertokens-node`, is there a way to modify the config for a `ThirdPartyEmailPassword` provider ...
b
In
supertokens-node
, is there a way to modify the config for a
ThirdPartyEmailPassword
provider from within a recipe override? More specifically, I am using a google as an identity provider and want to change the config params inside
thirdPartySignInUpPOST
hook. I will have a login hint unique to users that I need to pass to google. Im passing the hint in the request body and need to set it in this hook. I thought maybe I could modify the
input
that is passed to the
originalImplementation.thirdPartySignInUpPOST
call but it doesnt seem to contain the config data. I also made the config object passed to
ThirdPartyEmailPassword.Google
global so that I could modify it, but it looks like the provider gets initialized before the point its modified.
I have figured this out, but with a caveat that makes me think this could be improved. https://github.com/supertokens/supertokens-node/blob/db2588234df431959afa65546fc8db717dbd17fe/lib/build/recipe/thirdparty/providers/google.d.ts#L8-L10 I noticed that the
TypeThirdPartyProviderGoogleConfig['authorisationRedirect']['params']
in the config could be a function that gets the request instead of a string, so I used that.
Copy code
ts
          ThirdPartyEmailPassword.Google({
            clientId: config.clientId,
            clientSecret: config.clientSecret,
            scope: [ ... ],
            authorisationRedirect: {
              params: {
                login_hint: (request: any) => {
                  const params = new URLSearchParams(request.url)
                  const someParam = params.get('someParam')
                  
                  if(someParam){
                    return someParam
                  }
                  
                  // dont want to return anything here
                  return ''
                }
              }
            }
          })
The problem is that I only want to set the
login_hint
sometimes (when the parameter is added to the request). But currently I am forced to always set it or never set it. I see 2 ways this could be addressed: 1. The keys of
TypeThirdPartyProviderGoogleConfig['authorisationRedirect']['params']
(and the other provider configs) could be changed to return a string or undefined, then the keys with undefined values could be filtered out. This was my first instinct. 2.
TypeThirdPartyProviderGoogleConfig['authorisationRedirect']['params']
type could be expanded to also include a function with the request passed in which returns
params
(similar to the keys on params which I utilized above). Is there currently another workaround for this issue? Would you be open to a pull request implementing either of these?
Again, this brings up my original question: can the config be modified in the
thirdPartySignInUpPOST
hook? If so, that would be another way to solve this problem.
p
Hi, sorry for the late answer
I'll check this out in more detail tomorrow, meanwhile: - this may be worth checking out: https://supertokens.com/docs/thirdparty/common-customizations/sign-in-and-up/custom-providers - we are always open to PRs 🙂
r
Hey. @sattvikc can help here too
s
@blair6861 we are working on new interface which would make use cases like yours much easier. Meanwhile, you could solve this in 2 ways.
1. Override
authorisationUrlGET
, call the original implementation and then append
login_hint
param to the url (whenever you need it) and return it. 2. In the method you are currently doing which forces you to send a value, you could return empty string instead of undefined in cases you don't need it. the google provider will ignore it.
b
@sattvikc Glad to hear you are working on a new interface. Thank you. I am using the second way at the moment but will explore the first option too. I do see that google ignores an empty string but don't like that this solution relies on their implementation. Thanks again.
7 Views