Skip to content

Commit 4403c59

Browse files
authored
Merge pull request #8 from torusresearch/feat/sw-changes
Change sw registration route
2 parents 8fa6226 + b175541 commit 4403c59

File tree

5 files changed

+10
-9
lines changed

5 files changed

+10
-9
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ To allow your web app to retrieve keys:
77
1. Install the package
88
`npm i @toruslabs/torus-direct-web-sdk`
99

10-
2. Serve [service worker](public/sw.js) from `baseUrl` where baseUrl is the one passed while instantiating `TorusSdk` for specific login (example http://localhost:3000/). If you're already using a sw, pls ensure to port over the fetch override from [our service worker](public/sw.js)
10+
2. Serve [service worker](public/sw.js) from `baseUrl` where baseUrl is the one passed while instantiating `TorusSdk` for specific login (example http://localhost:3000/serviceworker/). If you're already using a sw, pls ensure to port over the fetch override from [our service worker](public/sw.js)
1111

12-
3. For browsers where service workers are not supported or if you wish to not use service workers, create and serve [redirect page](public/redirect.html) from `baseUrl/serviceworker/redirect` where baseUrl is the one passed while instantiating `TorusSdk` for specific login ( example http://localhost:3000/)
12+
3. For browsers where service workers are not supported or if you wish to not use service workers, create and serve [redirect page](public/redirect.html) from `baseUrl/redirect` where baseUrl is the one passed while instantiating `TorusSdk` for specific login ( example http://localhost:3000/serviceworker/)
1313

14-
4. At verifier's interface (where you obtain client id), please use `baseUrl/serviceworker/redirect` (eg: http://localhost:3000/serviceworker/redirect) as the redirect_uri where baseUrl is the one passed while instantiating `TorusSdk`
14+
4. At verifier's interface (where you obtain client id), please use `baseUrl/redirect` (eg: http://localhost:3000/serviceworker/redirect) as the redirect_uri where baseUrl is the one passed while instantiating `TorusSdk`
1515

1616
5. Instantiate the package with your own specific client-id
1717

1818
```js
1919
const torus = new TorusSdk({
20-
baseUrl: "http://localhost:3000",
20+
baseUrl: "http://localhost:3000/serviceworker/",
2121
GOOGLE_CLIENT_ID: "MY CLIENT ID GOOGLE",
2222
proxyContractAddress: "0x4023d2a0D330bF11426B12C6144Cfb96B7fa6183", // details for test net
2323
network: "ropsten", // details for test net
File renamed without changes.

examples/vue-app/src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default {
3131
methods: {
3232
async login() {
3333
try {
34-
const torus = new TorusSdk({ baseUrl: "http://localhost:3000/", GOOGLE_CLIENT_ID: '876733105116-i0hj3s53qiio5k95prpfmj0hp0gmgtor.apps.googleusercontent.com' });
34+
const torus = new TorusSdk({ baseUrl: "http://localhost:3000/serviceworker", GOOGLE_CLIENT_ID: '876733105116-i0hj3s53qiio5k95prpfmj0hp0gmgtor.apps.googleusercontent.com', enableLogging: true });
3535
await torus.init();
3636
const loginDetails = await torus.triggerLogin(this.selectedVerifier, this.selectedVerifier);
3737
this.console(loginDetails);

public/sw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ self.addEventListener("message", function (event) {
1212
self.addEventListener("fetch", function (event) {
1313
try {
1414
const url = new URL(event.request.url);
15-
if (url.pathname.includes("/serviceworker/redirect") && url.href.includes(getScope())) {
15+
if (url.pathname.includes("redirect") && url.href.includes(getScope())) {
1616
event.respondWith(
1717
new Response(
1818
new Blob(

src/login.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,22 @@ class DirectWebSDK {
2121
TWITCH_CLIENT_ID,
2222
REDDIT_CLIENT_ID,
2323
DISCORD_CLIENT_ID,
24-
baseUrl,
24+
baseUrl = "http://localhost:3000/serviceworker/",
2525
network = MAINNET,
2626
proxyContractAddress = "0x638646503746d5456209e33a2ff5e3226d698bea",
2727
enableLogging = false,
2828
} = {}) {
2929
this.isInitialized = false;
30+
const baseUri = new URL(baseUrl);
3031
this.config = {
3132
GOOGLE_CLIENT_ID,
3233
FACEBOOK_APP_ID,
3334
TWITCH_CLIENT_ID,
3435
REDDIT_CLIENT_ID,
3536
DISCORD_CLIENT_ID,
36-
baseUrl: baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`,
37+
baseUrl: baseUri.href.endsWith("/") ? baseUri.href : `${baseUri.href}/`,
3738
get redirect_uri() {
38-
return baseUrl.endsWith("/") ? `${baseUrl}serviceworker/redirect` : `${baseUrl}/serviceworker/redirect`;
39+
return `${this.baseUrl}redirect`;
3940
},
4041
};
4142
const torus = new Torus();

0 commit comments

Comments
 (0)