Skip to content

Commit

Permalink
fix: api content type
Browse files Browse the repository at this point in the history
  • Loading branch information
MrExplode committed Nov 28, 2023
1 parent 88c9df8 commit 3865351
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/lib/server/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ export async function useApi(
method: method
}
if (payload !== null) settings['body'] = JSON.stringify(payload)
if (token !== null) settings['headers'] = { Authorization: 'Bearer ' + token }

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const headers: any = {
'Content-Type': 'application/json'
}
if (token !== null) {
headers['Authorization'] = 'Bearer ' + token
}
settings.headers = headers

const response = fetch('https://api.unideb.tech' + endpoint, settings)
return (await response).json()
Expand Down
2 changes: 1 addition & 1 deletion src/routes/dash/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { PageServerLoad } from './$types'

export const load: PageServerLoad = async ({ cookies }) => {
const token = cookies.get('token')
if (token == undefined) throw redirect(307, '/dash/login')
if (token === undefined) throw redirect(307, '/dash/login')

const profileData = (await useApi(token as string, '/profile/info', 'GET')) as ProfileInfo
return {
Expand Down

0 comments on commit 3865351

Please sign in to comment.