Skip to content

Commit

Permalink
feat: use accessToken in request headers
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindis committed Sep 22, 2022
1 parent 0bda435 commit 1d30a64
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions services/api/climate/host.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import axios from 'axios';
import { getSession } from 'next-auth/react';

import env from '../../../env';

interface Props {
Expand All @@ -10,15 +12,22 @@ interface Props {

const { READING_BASE_URI } = env;

export const climateReading = ({ path, method, data, params }: Props) =>
axios({
url: `${READING_BASE_URI}${path}`,
method,
data,
params
})
.then(response => response.data)
.catch(() => null);
export const climateReading = async ({ path, method, data, params }: Props) => {
const session: any = await getSession();
return (
axios({
url: `${READING_BASE_URI}${path}`,
method,
data,
params,
headers: {
Authorization: `Bearer ${session?.accessToken}`
}
})
.then(response => response.data)
.catch(() => null)
);
}

export const climateReadingPost = (path: string, body: any) =>
climateReading({ path, method: 'POST', data: body });
Expand Down

0 comments on commit 1d30a64

Please sign in to comment.