Kevin CATHALY
commited on
Commit
•
b954b26
1
Parent(s):
269e9b5
add an api endpoint to get current user's informations (#763)
Browse files
src/routes/api/user/+server.ts
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
export async function GET({ locals }) {
|
2 |
+
if (locals.user) {
|
3 |
+
const res = {
|
4 |
+
id: locals.user._id,
|
5 |
+
username: locals.user.username,
|
6 |
+
name: locals.user.name,
|
7 |
+
email: locals.user.email,
|
8 |
+
avatarUrl: locals.user.avatarUrl,
|
9 |
+
hfUserId: locals.user.hfUserId,
|
10 |
+
};
|
11 |
+
|
12 |
+
return Response.json(res);
|
13 |
+
}
|
14 |
+
return Response.json({ message: "Must be signed in" }, { status: 401 });
|
15 |
+
}
|