Hi guys, is there by any chance an Interceptor for...
# general
m
Hi guys, is there by any chance an Interceptor for Angular yet? đŸ™‚ @martin8
r
Hey! Just for axios and fetch
If you use either of them, you can use our supertokens-website SDK
m
hmm, so is the SDK utlizing fetch and axios for more than just request interception and cookie setting?
r
Nothing else. It’s only for interception
m
ok then i'll make my own interceptor i think. The methods from the SDK like DoesSessionExist() should still work if I unterstand it correctly?
m
@Mr. Lurs Here's the interceptor I'm using; https://gist.github.com/martinAlt335/ad8fd339b5593e7d3fdd1cf3873507bf It is actually very simple and straightforward đŸ™‚ Found an interceptor covering retry-logic and hijacked it around Supertokens.
On line 35 & line 38, there are calls to our supertokens service. This supertokens-service being used is a simple service wrapping like two functions from the Supertokens SDK. Here's a gist of it; https://gist.github.com/martinAlt335/3424b56d0bb04761f463a0940a60d264 Line 12 you will see
apiDomain
make sure to change that to wherever your supertokens API is, we have that set in our Angular environment file. You will also see cookieService being used in the super-tokens service. It's this npm package; https://www.npmjs.com/package/ngx-cookie-service; make sure to add it to your module.
@rp Now that I think about it, in the second gist I shared, on line 24, we are manually deleting the
sIRTFrontend
cookie, when implementing we found that without deleting this, a user would not be signed out properly. Is there a function within Supertokens that handles this without us having to do it manually? I do recall when implementing, when calling the browser sdk sign out function, ‘sIRTFrontend’ cookie would be left as residue. Everything else seemed to work, manually removing this cookie looks like it does the trick. Is there anything should be done differently?
r
thanks @martin8 About the
sIRTFrontend
, we set it to
remove
if the user is not logged in because Safari clears frontend set cookies after 7 days of inactivity, due to which the frontend could not reliably determine if a user is logged in - since if it's missing, then we don't know if Safari cleared it or if the user actually logged out. So on logout, we set it to
remove
which means that the user is indeed logged out. If it's missing, then we query the refresh API, which would fail (if the user is logged out), and then we set it to
remove
.
m
Right, so its warranted that I should look into setting
sIRTFrontend
to
remove
rather than literally deleting the cookie?
r
yup. If you care about supporting safari. Then you should. You should be able to use all the helper functions provided in this file(https://github.com/supertokens/supertokens-website/blob/master/lib/ts/fetch.ts) for setting the frontend token, sIRTToken, doing the refresh call etc.. You just need to call those in the right places in your interceptor.
8 Views