Hello! We have a little problem about implementati...
# support-questions
b
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
hey @Biaz
Which recipe are you using?
b
ThirdPartyEmailPassword
We are using Angular on Ionic
r
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
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
Can I see the backend config you have provided?
and the frontend config as well
the supertokens.init part
i
we are using nest.js as backend
r
got it. and on the frontend what's the config like?
i
i'm going to send it too
this is the frontend init
r
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
Thanks for your help. we will try and if we have any problems we will open an issue on github
b
Hi! Look like it works! Thanks so much!!
r
Awesome!
r
Hi @Biaz do you have an example of how you did it?
r
hey @EdwinN1337 check this out here.
e
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
can you print out the value of
cookieString
?
e
its
null
r
@nkshah2 can probably help with this
e
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
sounds good
n
@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
this is the handler
Copy code
js
if (typeof window !== 'undefined') {
  supertokens.init({
    ...frontendConfig().appInfo,
    cookieHandler: capacitorCookieHandler,
    enableDebugLogs: process.env.APP_STAGE === 'development',
  })
}
n
Does the error have a stacktrace?
Also whats the value of
cookiesFromStorage
?
e
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
You can just make the function async. Shouldn’t make any difference to actual execution
n
@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
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
@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
i see. OK, we are working on a PR to make everything async
e
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
sounds good.
n
@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
clear, will do thanks!
ah capacitor is not relevent, we use nextjs + capacitor
n
You shouldnt need it, that example app uses a hash router which is why it needs it
e
right! okey thanks πŸ˜„
4 Views