Skip to content

Commit 4cfb00d

Browse files
example app fix (#815)
1 parent 28ee58d commit 4cfb00d

File tree

2 files changed

+30
-68
lines changed

2 files changed

+30
-68
lines changed

examples/with-thirdpartypasswordless-electron/api-server/index.js

Lines changed: 16 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -98,82 +98,30 @@ supertokens.init({
9898
);
9999
}
100100

101-
let htmlBody = getEmailBody(
102-
APP_NAME,
103-
Math.ceil(input.codeLifetime / 1000),
104-
finalUrlWithLinkCode,
105-
input.userInputCode,
106-
input.email
107-
);
108-
109-
/**
110-
* This will not work if you have not set up your email credentials in the .env file. Refer to .env.example
111-
* in this example app to know which environment variables you need to set.
112-
*/
113-
await mailTransporter.sendMail({
114-
html: htmlBody,
115-
to: input.email,
116-
from: `Team Supertokens <${process.env.NODEMAILER_USER}>`,
117-
sender: process.env.NODEMAILER_USER,
118-
subject: `Login to ${APP_NAME}`,
119-
});
101+
console.log("OTP is: " + input.userInputCode);
102+
console.log("Magic link is: " + input.urlWithLinkCode);
120103
},
121104
},
122105
},
123106
smsDelivery: {
124107
service: {
125108
sendSms: async function (input) {
126-
/*
127-
* Following is an example of how SMS sending setup can
128-
* be done using Twilio. The actual API that is being called
129-
* in this function is doing exactly the same thing.
130-
*/
131-
132-
/*
133-
const accountSid = process.env.TWILIO_ACCOUNT_SID;
134-
const authToken = process.env.TWILIO_AUTH_TOKEN;
135-
const twilioPhoneNumber = process.env.TWILIO_PHONE_NUMBER;
136-
let twilio = Twilio(accountSid, authToken);
137-
let message = "";
138-
if (input.urlWithLinkCode !== undefined && input.userInputCode !== undefined) {
139-
message = `Enter OTP: ${input.userInputCode} OR click this link: ${input.urlWithLinkCode} to login`;
140-
} else if (input.urlWithLinkCode !== undefined) {
141-
message = `Click this link: ${input.urlWithLinkCode} to login`;
142-
} else {
143-
message = `Enter OTP: ${input.userInputCode} to login`;
144-
}
145-
message += ` It will expire in ${input.codeLifetime} seconds.`;
146-
console.log(input.urlWithLinkCode)
147-
await twilio.messages.create({
148-
body: message,
149-
to: input.phoneNumber,
150-
from: twilioPhoneNumber
151-
});
152-
*/
153-
try {
154-
await axios({
155-
method: "post",
156-
baseURL: "https://api.supertokens.com",
157-
url: "/0/st/twilio/message",
158-
headers: {
159-
"api-version": "0",
160-
},
161-
data: {
162-
to: input.phoneNumber,
163-
appName: APP_NAME,
164-
codeLifetime: Math.ceil(input.codeLifetime / 1000),
165-
urlWithLinkCode: input.urlWithLinkCode,
166-
userInputCode: input.userInputCode,
167-
},
168-
});
169-
} catch (err) {
170-
if (err.response.status !== 429) {
171-
throw err;
172-
}
173-
throw Error(
174-
"Too many requests made for passwordless sign-in/up with phone number. The number of requests are restricted for this demo app. Please try again after 24 hours."
109+
if (input.urlWithLinkCode !== undefined) {
110+
/**
111+
* Electron uses file protocol for production builds. SuperTokens does not currently support
112+
* file protocol URLs, as a workaround we add a `/auth/verify` route that redirects to the
113+
* eletron app using deeplinking.
114+
*
115+
* Here we modify the magic link to use the apiDomain instead of the websiteDomain
116+
*/
117+
let currentUrlWithLinkCode = new URL(input.urlWithLinkCode);
118+
finalUrlWithLinkCode = input.urlWithLinkCode.replace(
119+
currentUrlWithLinkCode.origin,
120+
apiDomain
175121
);
176122
}
123+
console.log("OTP is: " + input.userInputCode);
124+
console.log("Magic link is: " + input.urlWithLinkCode);
177125
},
178126
},
179127
},

examples/with-thirdpartypasswordless-electron/src/renderer.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@ SuperTokens.init({
7373
windowHandler: getWindowHandler, // Refer to src/windowHandler.ts
7474
recipeList: [
7575
ThirdPartyPasswordless.init({
76+
override: {
77+
functions: (oI) => {
78+
return {
79+
...oI,
80+
getAuthorisationURLFromBackend: async (input) => {
81+
input = {
82+
...input,
83+
redirectURIOnProviderDashboard: getApiDomain() + "/auth/callback/" + input.thirdPartyId,
84+
};
85+
return oI.getAuthorisationURLFromBackend(input);
86+
},
87+
};
88+
},
89+
},
7690
signInUpFeature: {
7791
providers: [
7892
ThirdPartyPasswordless.Github.init(),

0 commit comments

Comments
 (0)