Rob Schilder
12/21/2022, 8:27 PMsupertokens-web-js
to supertokens-website
. I will make a thread!supertokens-website
we had to manually call the APIs.
For the third party login, I used the function:
export const getThirdPartyAuthUrl = async ({
thirdPartyId,
}: {
thirdPartyId: 'google' | 'facebook' | 'apple'
}): Promise<GetThirdPartyAuthUrlResponse> =>
fetch(
`${url}/api/auth/authorisationurl?thirdPartyId=${thirdPartyId}`,
{
method: 'GET',
headers: {
'Content-Type': 'application/json',
rid: 'thirdpartyemailpassword',
},
},
).then(res => res.json())
And then onThirdPartyLogin I would call:
export const onThirdPartyLogin = async ({
provider,
platform,
repository,
}: {
repository: Repository
provider: 'google' | 'facebook' | 'apple'
platform: Platform
}) => {
const response = await getThirdPartyAuthUrl({
thirdPartyId: provider,
repository,
})
if (response.status === 'OK') {
const url = new URL(response.url)
if (platform === 'APP') {
console.log('app came here')
url.searchParams.append(
'redirect_uri',
`${
repository === 'CONTRACTOR'
? REDIRECT_URL_CONTRACTOR
: REDIRECT_URL_CLIENT
}/api/auth/redirect?provider=${provider}`,
)
window.open(url)
}
if (platform !== 'APP') {
url.searchParams.append(
'redirect_uri',
`${
repository === 'CONTRACTOR'
? FRONTEND_URL_CONTRACTOR
: FRONTEND_URL_CLIENT
}/auth/callback/${provider}`,
)
window.location.href = url.href
}
}
if (response.status !== 'OK') {
alert(`Er is iets misgegaan met inloggen via ${provider}, probeer opnieuw`)
}
}
Because I am using Capacitor as well, I had to have different redirect URI's, I couldn't just redirect to the callback, had to go to API first.
Should I overwrite in supertokens-web-js
or something? And what functions should I use?nkshah2
12/22/2022, 4:34 AMCookieHandlerInterface
and WindowHandlerInterface
, the supertokens-web-js
SDK inherits types from supertokens-website
so you can keep that as it is.
supertokens-website
is a dependency of supertokens-web-js
so the import will still be available after migratingRob Schilder
12/22/2022, 6:14 AMnkshah2
12/22/2022, 6:18 AMexport const getThirdPartyAuthUrl = async ({
thirdPartyId,
}: {
thirdPartyId: 'google' | 'facebook' | 'apple'
}): Promise<GetThirdPartyAuthUrlResponse> =>
fetch(
`${url}/api/auth/authorisationurl?thirdPartyId=${thirdPartyId}`,
{
method: 'GET',
headers: {
'Content-Type': 'application/json',
rid: 'thirdpartyemailpassword',
},
},
).then(res => res.json())
Can be replaced by
import ThirdPartyEmailPassword from "supertokens-web-js/recipe/thirdpartyemailpassword"
async function getThirdPartyURL(thirdPartyId: 'google' | 'facebook' | 'apple') {
return await ThirdPartyEmailPassword.getAuthorisationURLWithQueryParamsAndSetState({
providerId: thirdPartyId,
authorisationURL: "<REDIRECT_URI_FOR_SOCIAL_LOGIN>"
})
}
Rob Schilder
12/22/2022, 6:23 AMnkshah2
12/22/2022, 6:23 AM