Skip to content

Commit b954b26

Browse files
authored
add an api endpoint to get current user's informations (#763)
1 parent 269e9b5 commit b954b26

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/routes/api/user/+server.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

0 commit comments

Comments
 (0)