https://supertokens.com/ logo
b

Biaz

05/26/2022, 2:52 PM
Hello! We have a little problem about implementation of Supetokens on Ionic/Capacitor. In particular about the native versions of it. Its like if the back-end side doesn't allow customScheme (ex: capacitor://app.id/home). After the basic implementation of docs we have this error on iOS: Unhandled Promise rejection: โ€“ "Please provide a valid domain name" Can some help me please? Thanks in advance!
r

rp

05/26/2022, 2:53 PM
hey @Biaz
Which recipe are you using?
b

Biaz

05/26/2022, 2:55 PM
ThirdPartyEmailPassword
We are using Angular on Ionic
r

rp

05/26/2022, 3:02 PM
The websiteDomain in the appInfo on the backend is used for generating reset password and email verification links. You can set this to your app's website domain. In order to deep link the reset password and email verification links to point to your app, you can override the function on the backend that sends these emails and replace the domain link with the capacitor deep link. For social login providers, some of them may not accept non http redirect callbacks, so you want to point them to your api server URL and then redirect the user to your app via a deeplink like shown here: https://github.com/supertokens/supertokens-auth-react/blob/master/examples/with-thirdpartypasswordless-electron/api-server/index.js#L220
i

Impecorator

05/26/2022, 3:12 PM
Hi, i'm a colleague of @Biaz. We have problems when we try to signin with a mail and passord with recipe ThirdPartyEmailPassword. When we launch the IOS emulator, the app is hosted on 'capacitor://localhost', but it seems to be unsupported because the request respond with error "Unhandled Promise rejection: โ€“ Please provide a valid domain name".
r

rp

05/26/2022, 3:12 PM
Can I see the backend config you have provided?
and the frontend config as well
the supertokens.init part
i

Impecorator

05/26/2022, 3:14 PM
we are using nest.js as backend
r

rp

05/26/2022, 3:14 PM
got it. and on the frontend what's the config like?
i

Impecorator

05/26/2022, 3:14 PM
i'm going to send it too
this is the frontend init
r

rp

05/26/2022, 3:23 PM
hmm.
I think you will have to provide custom cookie and window handler for the frontend SDK. Examples are: - cookieHandler: https://github.com/supertokens/supertokens-auth-react/blob/master/examples/with-thirdpartypasswordless-electron/src/cookieHandler.ts - windowHandler: https://github.com/supertokens/supertokens-auth-react/blob/master/examples/with-thirdpartypasswordless-electron/src/windowHandler.ts Both of these will need to be provided to the supertokens.init on the frontend (the init object should have an argument for them)
if these examples are not good enough, please feel free to open an issue about this on our github and we will provide an example for this sometime in the coming days
i

Impecorator

05/26/2022, 3:27 PM
Thanks for your help. we will try and if we have any problems we will open an issue on github
b

Biaz

05/30/2022, 1:43 PM
Hi! Look like it works! Thanks so much!!
r

rp

05/30/2022, 1:43 PM
Awesome!
r

Rob Schilder

06/09/2022, 2:08 PM
Hi @Biaz do you have an example of how you did it?
r

rp

06/09/2022, 2:09 PM
hey @EdwinN1337 check this out here.
e

EdwinN1337

06/09/2022, 2:32 PM
We get this error, since we had to convert to the capacitor implementation
Copy code
js
async function setCookieToStorage(cookieString: string) {
  const cookieName = cookieString.split(';')[0].split('=')[0]
  const cookiesFromStorage = await Storage.get({ key: frontendCookiesKey })
r

rp

06/09/2022, 2:33 PM
can you print out the value of
cookieString
?
e

EdwinN1337

06/09/2022, 2:36 PM
its
null
r

rp

06/09/2022, 2:37 PM
@nkshah2 can probably help with this
e

EdwinN1337

06/09/2022, 2:38 PM
I'll dive deeper into it tommorow ๐Ÿ˜‰ Have to close my computer now. If you got any idea @nkshah2 let me know, i'll respond tommorow
@Impecorator how did you do it with Capacitor Storage? Might help us even faster ๐Ÿ˜„
r

rp

06/09/2022, 2:38 PM
sounds good
n

nkshah2

06/09/2022, 2:40 PM
@EdwinN1337 when you get a chance can you post the code for how you are calling SuperTokens.init (along with the custom cookie handler)
e

EdwinN1337

06/09/2022, 2:41 PM
this is the handler
Copy code
js
if (typeof window !== 'undefined') {
  supertokens.init({
    ...frontendConfig().appInfo,
    cookieHandler: capacitorCookieHandler,
    enableDebugLogs: process.env.APP_STAGE === 'development',
  })
}
n

nkshah2

06/09/2022, 2:48 PM
Does the error have a stacktrace?
Also whats the value of
cookiesFromStorage
?
e

EdwinN1337

06/09/2022, 6:09 PM
ah i got it
my bad, capacitor returns an object
Can I safely ignore this type error?
getCookiesFromStorage()
is a async operation now due to capacitor/promise
Will try to get the rest working tommorow!
r

rp

06/09/2022, 6:12 PM
You can just make the function async. Shouldnโ€™t make any difference to actual execution
n

nkshah2

06/10/2022, 4:05 AM
@EdwinN1337 actually the function needs to be synchronous because itโ€™s called on the UI layer. Does capacitor expose sync versions of the storage APIs?
r

rp

06/10/2022, 4:09 AM
Hey @EdwinN1337 I had misread the error. Adding async would not make the above work
Is there a sync version of getting cookies that capacitor provides?
e

EdwinN1337

06/10/2022, 6:52 AM
@rp there is no sync way, we can use
window.localStorage
but con of using window is that mobile Os periodically clears the data... and we need to persist it ๐Ÿ˜ฆ
r

rp

06/10/2022, 6:52 AM
i see. OK, we are working on a PR to make everything async
e

EdwinN1337

06/10/2022, 6:54 AM
Great! so i'll try to get everything working with window instead and will wait for the PR and move to the Storage plugin.
r

rp

06/10/2022, 7:01 AM
sounds good.
n

nkshah2

06/10/2022, 7:04 AM
@EdwinN1337 Also in the meantime if you arent using the language translation feature you can safely return nothing from getCookieSync and we will let you know once the changes are done
e

EdwinN1337

06/10/2022, 7:07 AM
clear, will do thanks!
ah capacitor is not relevent, we use nextjs + capacitor
n

nkshah2

06/10/2022, 7:10 AM
You shouldnt need it, that example app uses a hash router which is why it needs it
e

EdwinN1337

06/10/2022, 7:10 AM
right! okey thanks ๐Ÿ˜„
3 Views