supertokens / supertokens-web-js

SuperTokens SDK for vanilla JS for all recipes
Other
59 stars 10 forks source link

how to make supertokens-web-js works with uniapp #73

Closed leoujz closed 2 years ago

leoujz commented 2 years ago

My issuse is that I want to make supertokens frontend sdk working in uni-app environment (js + vue), which is a platform to make wechat/alipay miniprogram. Firstly I tried supertokens-web-js, which use supertokens-website library for session managment. But the supertokens-website is incompatible with uniapp environment, because uniapp mini program environment does support window.fetch.

I want to modify the source code or override some functions of supertokens-web-js to make it work with uniapp. I think one of the key points is using localstorage instead of cookies and adding interceptors to http request. For localstorage problem, I already tried the localstorage example and it works.

uniapp use code uni.request() to do http request, I want to overide the default http request behavior in supertokens-web-js.

I know that you might not be familiar with uniapp, but some hints would help a lot.

rishabhpoddar commented 2 years ago

Does uni use XHR underneath? Cause supertokens-website also adds interceptors to XHR when the init function is called.

leoujz commented 2 years ago

Not really XHR underneath, uni app use uni.request and will make it compatible with multi platforms, like ios, android, web, desktop, miniprograms of many differnent platforms. Is there a way to override the HTTP request of supertokens-web-js, and let me implement it on my own.

rishabhpoddar commented 2 years ago

Well yea. If uni is not using XHR, nor is it using fetch, then you supertokens-website repo won't interfere with the requests anyway.

For things like checking if a session exists etc, you can override the doesSessionExist function using the override config when you do supertokens.init. There are other functions in the interface too which you could override.

rishabhpoddar commented 2 years ago

Closing this issue, since it's not really a bug in SuperTokens