Commit 33bb1e43 authored by Matthieu Christian's avatar Matthieu Christian
Browse files

feat: adds a security dotenv in project

parent e9939c1b
# Configurações do APLICATIVO
APP_EMAIL=
APP_PASSWORD=
# Configurações de USUÁRIO
USER_EMAIL=
USER_PASSWORD=
\ No newline at end of file
......@@ -11,6 +11,7 @@
"license": "ISC",
"dependencies": {
"axios": "^0.24.0",
"dotenv": "^10.0.0",
"uuid": "^8.3.2"
}
}
import dotenv from 'dotenv';
import { v1 } from 'uuid';
import { api } from '../api/services/SGEOLConnection.js';
import { login, userToken } from './login.js';
dotenv.config();
const createAInstance = async (coordinates, type) => {
const { token, authorizationCode } = await login();
const { token, authorizationCode } = await login(
process.env.APP_EMAIL,
process.env.APP_PASSWORD
);
const { access_token } = await userToken(token, authorizationCode);
const { access_token } = await userToken(
process.env.USER_EMAIL,
process.env.USER_PASSWORD,
token,
authorizationCode
);
const instance = {
'@context': [
......
import { api } from '../api/services/SGEOLConnection.js';
export const login = async () => {
export const login = async (appEmail, password) => {
try {
const { data } = await api.post(
'/security/auth/login/app',
new URLSearchParams({
username: 'app_devboard@test.com',
password: '1234',
username: String(appEmail),
password: String(password),
})
);
return validadeToken(data.access_token);
} catch (error) {
console.log(error.data.message);
console.log(error);
}
};
......@@ -27,17 +27,22 @@ const validadeToken = async token => {
idApp: validate.id,
};
} catch (error) {
console.log(error.response.data);
console.log(error);
}
};
export const userToken = async (token, applicationToken) => {
export const userToken = async (
userEmail,
password,
token,
applicationToken
) => {
try {
const { data: user } = await api.post(
`/security/auth/login/user`,
new URLSearchParams({
username: 'manager@example.com',
password: '1234',
username: String(userEmail),
password: String(password),
'application-token': token,
}),
{
......@@ -50,7 +55,7 @@ export const userToken = async (token, applicationToken) => {
return user;
} catch (err) {
console.log(err.request.data);
console.log(err);
}
};
......
......@@ -9,6 +9,11 @@ axios@^0.24.0:
dependencies:
follow-redirects "^1.14.4"
dotenv@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81"
integrity sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==
follow-redirects@^1.14.4:
version "1.14.5"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.5.tgz#f09a5848981d3c772b5392309778523f8d85c381"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment