-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #141 from ES2-UFPI/gisele#118
Desenvolvendo issue #118
- Loading branch information
Showing
13 changed files
with
91 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,39 @@ | ||
import express from 'express'; | ||
import cors from 'cors'; | ||
import {routes} from "./routes"; | ||
import { routes } from "./routes"; | ||
import * as jsonwebtoken from 'jsonwebtoken'; | ||
require('dotenv/config'); | ||
import './database'; | ||
|
||
const app = express(); | ||
const app = express(); | ||
|
||
app.use(cors({ | ||
origin: '*', | ||
credentials: false | ||
})) | ||
app.use(express.json()); | ||
|
||
app.use(async (req, res, next) => { | ||
|
||
if (req.url === '/users/authentication') return next(); | ||
if (req.url === '/professionals' && req.method === 'POST') return next(); | ||
if (req.url === '/clients' && req.method === 'POST') return next(); | ||
|
||
const accessToken = req.headers['authorization']; | ||
|
||
try { | ||
if (accessToken) { | ||
const user = await jsonwebtoken.verify(accessToken, process.env.JWT_SECRET || ''); | ||
app.set('user', user); | ||
} | ||
} catch (err) { | ||
// res.status(500).json({ error: 'Token de acesso inválido' }) | ||
} | ||
next(); | ||
}) | ||
|
||
app.use(routes); | ||
|
||
app.listen(3333,()=>console.log("Server Started!")); | ||
console.log(jsonwebtoken.sign({ id: '1' }, process.env.JWT_SECRET || '')) | ||
|
||
app.listen(3333, () => console.log("Server Started!")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
import axios from "axios"; | ||
import { store } from '../store'; | ||
import { IP } from '../../evironment'; | ||
|
||
const api = axios.create({ | ||
baseURL: `http://192.168.0.114:3333/`, | ||
headers:{ | ||
'accept': 'application/json', | ||
'Access-Control-Allow-Origin': '*', | ||
headers: { | ||
'Access-Control-Allow-Origin': '*', | ||
accept: 'application/json', | ||
Authorization: store.getState().auth.accessToken, | ||
} | ||
|
||
}); | ||
|
||
export default api; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
interface Tokens { | ||
accessToken: string | ||
refreshToken: string | ||
} | ||
|
||
export const SetTokens = (tokens: Tokens) => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters