Skip to content

Commit

Permalink
feat: send auth over header when loggedin
Browse files Browse the repository at this point in the history
  • Loading branch information
iaurg committed Oct 29, 2023
1 parent bd73436 commit 1d51006
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 0 additions & 1 deletion frontend/src/contexts/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export const AuthProvider = ({ children }: AuthProviderProps) => {
withCredentials: true,
})
.then((response) => {
console.log("response", response);
setUser(response.data);
})
.catch((error) => {
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ import { parseCookies } from "nookies";
type Context = undefined | GetServerSidePropsContext;

export function setupAPIClient(ctx: Context = undefined) {
const cookies = parseCookies(ctx);

const api = axios.create({ baseURL: process.env.NEXT_PUBLIC_API_URL });

api.interceptors.request.use(
(config) => {
const { accessToken } = nookies.get(null, "accesssToken");
const payload: TokenPayload = jwt_decode(accessToken);

if (accessToken) {
config.headers["Authorization"] = `Bearer ${accessToken}`;
}

return config;
},

Expand Down

0 comments on commit 1d51006

Please sign in to comment.