Skip to content

Commit

Permalink
📧 Added public url variable for emails (#2967)
Browse files Browse the repository at this point in the history
* Added public url variable for emails

* Fixed base url for reset password - the current implementation overrides possibly existing path

* Change variable name to editorUrl

* Using correct name editorUrl for emails

* Changed variable description

* Improved base url naming and appending path so it remains consistent

* Removed trailing slash from editor base url
  • Loading branch information
krynble authored Mar 11, 2022
1 parent 55255be commit 94edba2
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
6 changes: 6 additions & 0 deletions packages/cli/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,12 @@ const config = convict({
env: 'N8N_SSL_CERT',
doc: 'SSL Cert for HTTPS Protocol',
},
editorBaseUrl: {
format: String,
default: '',
env: 'N8N_EDITOR_BASE_URL',
doc: 'Public URL where the editor is accessible; path will be concatenated to this base. Also used for emails sent from n8n.',
},

security: {
excludeEndpoints: {
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ export interface IN8nUISettings {
};
timezone: string;
urlBaseWebhook: string;
urlBaseEditor: string;
versionCli: string;
n8nMetadata?: {
[key: string]: string | number | undefined;
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ import { ExecutionEntity } from './databases/entities/ExecutionEntity';
import { SharedWorkflow } from './databases/entities/SharedWorkflow';
import { AUTH_COOKIE_NAME, RESPONSE_ERROR_MESSAGES } from './constants';
import { credentialsController } from './api/credentials.api';
import { isEmailSetUp } from './UserManagement/UserManagementHelper';
import { getInstanceBaseUrl, isEmailSetUp } from './UserManagement/UserManagementHelper';

require('body-parser-xml')(bodyParser);

Expand Down Expand Up @@ -296,6 +296,7 @@ class App {
maxExecutionTimeout: this.maxExecutionTimeout,
timezone: this.timezone,
urlBaseWebhook,
urlBaseEditor: getInstanceBaseUrl(),
versionCli: '',
oauthCallbackUrls: {
oauth1: `${urlBaseWebhook}${this.restEndpoint}/oauth1-credential/callback`,
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/UserManagement/UserManagementHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export async function getInstanceOwner(): Promise<User> {
* Return the n8n instance base URL without trailing slash.
*/
export function getInstanceBaseUrl(): string {
const baseUrl = GenericHelpers.getBaseUrl();
const editorBaseUrl = config.get('editorBaseUrl');
const baseUrl = editorBaseUrl ? editorBaseUrl + config.get('path') : GenericHelpers.getBaseUrl();
return baseUrl.endsWith('/') ? baseUrl.slice(0, baseUrl.length - 1) : baseUrl;
}

Expand Down
7 changes: 3 additions & 4 deletions packages/cli/src/UserManagement/routes/passwordReset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import { LoggerProxy as Logger } from 'n8n-workflow';

import { Db, InternalHooksManager, ResponseHelper } from '../..';
import { N8nApp } from '../Interfaces';
import { validatePassword } from '../UserManagementHelper';
import { getInstanceBaseUrl, validatePassword } from '../UserManagementHelper';
import * as UserManagementMailer from '../email';
import type { PasswordResetRequest } from '../../requests';
import { issueCookie } from '../auth/jwt';
import { getBaseUrl } from '../../GenericHelpers';
import config = require('../../../config');

export function passwordResetNamespace(this: N8nApp): void {
Expand Down Expand Up @@ -73,8 +72,8 @@ export function passwordResetNamespace(this: N8nApp): void {

await Db.collections.User!.update(id, { resetPasswordToken, resetPasswordTokenExpiration });

const baseUrl = getBaseUrl();
const url = new URL('/change-password', baseUrl);
const baseUrl = getInstanceBaseUrl();
const url = new URL(`${baseUrl}/change-password`);
url.searchParams.append('userId', id);
url.searchParams.append('token', resetPasswordToken);

Expand Down

0 comments on commit 94edba2

Please sign in to comment.