Skip to content

Commit

Permalink
Add option to pass x-request-language header for passwordless (#873)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjmcgrath authored Jun 26, 2023
1 parent c7f10fe commit 1380f55
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/auth/PasswordlessAuthenticator.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ function getParamsFromOptions(options) {
if (!options || typeof options !== 'object') {
return params;
}
if (options.forwardedFor) {
if (options.forwardedFor || options.requestLanguage) {
params._requestCustomizer = function (req) {
req.set('auth0-forwarded-for', options.forwardedFor);
options.forwardedFor && req.set('auth0-forwarded-for', options.forwardedFor);
options.requestLanguage && req.set('x-request-language', options.requestLanguage);
};
}
return params;
Expand Down Expand Up @@ -214,6 +215,7 @@ class PasswordlessAuthenticator {
* @param {string} userData.send The type of email to be sent.
* @param {object} [options] Additional options.
* @param {string} [options.forwardedFor] Value to be used for auth0-forwarded-for header
* @param {string} [options.requestLanguage] Specify a language for the message area.
* @param {Function} [cb] Method callback.
* @returns {Promise|undefined}
*/
Expand Down Expand Up @@ -270,6 +272,7 @@ class PasswordlessAuthenticator {
* @param {string} userData.phone_number User phone number.
* @param {object} [options] Additional options.
* @param {string} [options.forwardedFor] Value to be used for auth0-forwarded-for header
* @param {string} [options.requestLanguage] Specify a language for the message area.
* @param {Function} [cb] Method callback.
* @returns {Promise|undefined}
*/
Expand Down
38 changes: 38 additions & 0 deletions test/auth/passwordless.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,25 @@ describe('PasswordlessAuthenticator', () => {
.catch(done);
});

it('should make it possible to pass x-request-language header', function (done) {
nock.cleanAll();

const request = nock(API_URL)
.post(path, function () {
return this.headers['x-request-language'] === 'fr';
})
.reply(200);

this.authenticator
.sendEmail(userData, { requestLanguage: 'fr' })
.then(() => {
expect(request.isDone()).to.be.true;

done();
})
.catch(done);
});

it('should make request with proxy', async () => {
nock.cleanAll();

Expand Down Expand Up @@ -916,6 +935,25 @@ describe('PasswordlessAuthenticator', () => {
.catch(done);
});

it('should make it possible to pass x-request-language header', function (done) {
nock.cleanAll();

const request = nock(API_URL)
.post(path, function () {
return this.headers['x-request-language'] === 'fr';
})
.reply(200);

this.authenticator
.sendSMS(userData, { requestLanguage: 'fr' })
.then(() => {
expect(request.isDone()).to.be.true;

done();
})
.catch(done);
});

it('should make request with proxy', async () => {
nock.cleanAll();

Expand Down

0 comments on commit 1380f55

Please sign in to comment.