Skip to content

Commit

Permalink
fix: rename environment variable calls to use process.env instead of …
Browse files Browse the repository at this point in the history
…import.meta.env
  • Loading branch information
PauloUbirajara committed Apr 28, 2024
1 parent d18d9ce commit 7ea94ce
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
12 changes: 10 additions & 2 deletions src/lib/repositories/baseRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import { getFilteredUrlSearchParams } from "../../helpers/url";
import type { IModelRepository } from "../../protocols/modelRepository";

type BaseRepositoryDTO = {
accessToken: string | undefined;
url: string;
accessToken?: string | undefined;
url?: string;
};

export abstract class BaseRepository implements IModelRepository {
Expand All @@ -31,6 +31,14 @@ export abstract class BaseRepository implements IModelRepository {
);
}

if (input.url === undefined) {
throw new Error("Url not in base repository");
}

if (input.accessToken === undefined) {
throw new Error("Access token not set in base repository");
}

this.url = input.url;

this.headers = {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/repositories/categoryRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class CategoryRepository
constructor(input: CategoryRepositoryDTO) {
super({
accessToken: input.accessToken,
url: import.meta.env.VITE_API_CATEGORIES_ENDPOINT,
url: process.env.VITE_API_CATEGORIES_ENDPOINT,
});
}
}
2 changes: 1 addition & 1 deletion src/lib/repositories/currencyRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class CurrencyRepository
constructor(input: CurrencyRepositoryDTO) {
super({
accessToken: input.accessToken,
url: import.meta.env.VITE_API_CURRENCIES_ENDPOINT,
url: process.env.VITE_API_CURRENCIES_ENDPOINT,
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/repositories/transactionRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class TransactionRepository
constructor(input: TransactionRepositoryDTO) {
super({
accessToken: input.accessToken,
url: import.meta.env.VITE_API_TRANSACTIONS_ENDPOINT,
url: process.env.VITE_API_TRANSACTIONS_ENDPOINT,
});
}
}
2 changes: 1 addition & 1 deletion src/lib/repositories/walletRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class WalletRepository
constructor(input: WalletRepositoryDTO) {
super({
accessToken: input.accessToken,
url: import.meta.env.VITE_API_WALLETS_ENDPOINT,
url: process.env.VITE_API_WALLETS_ENDPOINT,
});
}

Expand Down
12 changes: 6 additions & 6 deletions src/utils/jwtAuth/backendJwtAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { constants } from "http2";

class BackendJWTAuth implements IJWTAuth {
async login(credentials: LoginCredentials): Promise<LoginResponse> {
const url = import.meta.env.VITE_AUTH_LOGIN_URL;
const url = process.env.VITE_AUTH_LOGIN_URL;

if (url === undefined) {
return Promise.reject("URL para login de usuários não definida.");
Expand All @@ -35,7 +35,7 @@ class BackendJWTAuth implements IJWTAuth {
}

async register(credentials: RegisterCredentials): Promise<RegisterResponse> {
const url = import.meta.env.VITE_AUTH_REGISTER_URL;
const url = process.env.VITE_AUTH_REGISTER_URL;

if (url === undefined) {
return Promise.reject("URL para cadastro de usuários não definida.");
Expand All @@ -60,7 +60,7 @@ class BackendJWTAuth implements IJWTAuth {
async sendResetPassword(
credentials: SendResetPasswordCredentials,
): Promise<void> {
const url = import.meta.env.VITE_AUTH_SEND_RESET_PASSWORD_URL;
const url = process.env.VITE_AUTH_SEND_RESET_PASSWORD_URL;

if (url === undefined) {
return Promise.reject(
Expand Down Expand Up @@ -89,7 +89,7 @@ class BackendJWTAuth implements IJWTAuth {
async resetPassword(
credentials: ResetPasswordCredentials,
): Promise<ResetPasswordResponse> {
const url = import.meta.env.VITE_AUTH_RESET_PASSWORD_URL;
const url = process.env.VITE_AUTH_RESET_PASSWORD_URL;

if (url === undefined) {
return Promise.reject("URL para redefinição de senha não definida.");
Expand All @@ -113,7 +113,7 @@ class BackendJWTAuth implements IJWTAuth {
}

async validate(accessToken: string): Promise<boolean> {
const url = import.meta.env.VITE_AUTH_VALIDATION_URL;
const url = process.env.VITE_AUTH_VALIDATION_URL;

if (url === undefined) {
return Promise.reject("URL para validação de usuário não definida.");
Expand All @@ -135,7 +135,7 @@ class BackendJWTAuth implements IJWTAuth {
}

async refresh(refreshToken: string): Promise<string | null> {
const url = import.meta.env.VITE_AUTH_REFRESH_TOKEN_URL;
const url = process.env.VITE_AUTH_REFRESH_TOKEN_URL;

if (url === undefined) {
return Promise.reject("URL para validação de usuário não definida.");
Expand Down

0 comments on commit 7ea94ce

Please sign in to comment.