-
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.
- Loading branch information
Showing
6 changed files
with
66 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
const API_URL = '/api/getme'; | ||
|
||
export async function getMe(token: string) { | ||
try { | ||
const response = await fetch(API_URL, { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Authorization': `Bearer ${token}` | ||
} | ||
}); | ||
try { | ||
const response = await fetch(API_URL, { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${token}` | ||
} | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error('Failed to fetch user data'); | ||
} | ||
if (!response.ok) { | ||
throw new Error('Failed to fetch user data'); | ||
} | ||
|
||
const data = await response.json(); | ||
return data; | ||
} catch (error) { | ||
console.error(error); | ||
throw error; | ||
} | ||
} | ||
const data = await response.json(); | ||
return data; | ||
} catch (error) { | ||
console.error(error); | ||
throw error; | ||
} | ||
} |
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,24 +1,24 @@ | ||
import type { RequestHandler } from '@sveltejs/kit'; | ||
|
||
export const GET: RequestHandler = async ({ request }) => { | ||
const response = await fetch(`${import.meta.env.VITE_SERVER_URL}/api/v1/auth/me`, { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Authorization': request.headers.get('Authorization') || '' | ||
} | ||
}); | ||
const response = await fetch(`${import.meta.env.VITE_SERVER_URL}/api/v1/auth/me`, { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: request.headers.get('Authorization') || '' | ||
} | ||
}); | ||
|
||
if (!response.ok) { | ||
return new Response(JSON.stringify({ error: 'Failed to fetch user data' }), { | ||
status: response.status, | ||
headers: { 'Content-Type': 'application/json' } | ||
}); | ||
} | ||
if (!response.ok) { | ||
return new Response(JSON.stringify({ error: 'Failed to fetch user data' }), { | ||
status: response.status, | ||
headers: { 'Content-Type': 'application/json' } | ||
}); | ||
} | ||
|
||
const data = await response.json(); | ||
return new Response(JSON.stringify(data), { | ||
status: 200, | ||
headers: { 'Content-Type': 'application/json' } | ||
}); | ||
}; | ||
const data = await response.json(); | ||
return new Response(JSON.stringify(data), { | ||
status: 200, | ||
headers: { 'Content-Type': 'application/json' } | ||
}); | ||
}; |
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