Skip to content

Commit

Permalink
fix(server): consolidate basepath, remove version
Browse files Browse the repository at this point in the history
  • Loading branch information
jrea committed Aug 28, 2024
1 parent 26018c3 commit cd3d696
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 28 deletions.
9 changes: 5 additions & 4 deletions packages/server/src/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function serverAuth(
}

info('Obtaining providers for', email);
const sessionUrl = new URL(`${config.api.localPath}/api/auth/providers`);
const sessionUrl = new URL(`${config.api.basePath}/api/auth/providers`);
const sessionReq = new Request(sessionUrl, {
method: 'GET',
headers: new Headers({
Expand All @@ -38,12 +38,12 @@ export default function serverAuth(
try {
providers = await sessionRes?.json();
} catch (e) {
info(sessionRes);
info(sessionUrl, sessionRes);
error(e);
}

info('Obtaining csrf');
const csrf = new URL(`${config.api.localPath}/api/auth/csrf`);
const csrf = new URL(`${config.api.basePath}/api/auth/csrf`);
const csrfReq = new Request(csrf, {
method: 'GET',
headers: new Headers({
Expand All @@ -56,10 +56,11 @@ export default function serverAuth(
const json = (await csrfRes?.json()) ?? {};
csrfToken = json?.csrfToken;
} catch (e) {
info(sessionUrl, csrfRes);
error(e, csrfRes);
}

const { credentials } = providers;
const { credentials } = providers ?? {};

const csrfCookie = csrfRes?.headers.get('set-cookie');

Expand Down
11 changes: 0 additions & 11 deletions packages/server/src/utils/Config/envVars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,6 @@ export const getTenantId = (cfg: EnvConfig): string | null => {
return null;
};

export const getLocal = (cfg: EnvConfig) => {
const { config, logger } = cfg;

if (process.env.NILEDB_LOCAL) {
const { info } = Logger(config, '[local]');
logger && info(logger, 'NILEDB_LOCAL', process.env.NILEDB_LOCAL);
const apiUrl = new URL(process.env.NILEDB_LOCAL);
return apiUrl.href;
}
return 'http://localhost:3000';
};
/**
* @param cfg various overrides
* @returns the url for REST to use
Expand Down
13 changes: 0 additions & 13 deletions packages/server/src/utils/Config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
getTenantId,
getToken,
getUsername,
getLocal,
} from './envVars';

export type ConfigRoutes = {
Expand All @@ -31,27 +30,19 @@ export type ConfigRoutes = {
class ApiConfig {
public cookieKey?: string;
public basePath?: string | undefined;
public version?: number;
public localPath?: string;
private _token?: string;
constructor({
basePath,
cookieKey,
token,
version,
localPath,
}: {
basePath?: string | undefined;
cookieKey: string;
token: string | undefined;
version: number;
localPath: string;
}) {
this.basePath = basePath;
this.cookieKey = cookieKey;
this.version = version;
this._token = token;
this.localPath = localPath ?? 'http://localhost:3000';
}

public get token(): string | undefined {
Expand Down Expand Up @@ -128,8 +119,6 @@ export class Config {
basePath,
cookieKey: config?.api?.cookieKey ?? 'token',
token: getToken({ config }),
version: config?.api?.version ?? 2,
localPath: getLocal(envVarConfig),
});
this.db = {
user: this.user,
Expand Down Expand Up @@ -214,8 +203,6 @@ export class Config {
basePath,
cookieKey: config?.api?.cookieKey ?? 'token',
token: getToken({ config }),
version: config?.api?.version ?? 2,
localPath: getLocal(envVarConfig),
});
this.db = {
user: this.user,
Expand Down

0 comments on commit cd3d696

Please sign in to comment.