this post was submitted on 11 Jan 2025
4 points (100.0% liked)

Lemmy Apps

5586 readers
74 users here now

A home for discussion of Lemmy apps and tools for all platforms.

RULES:


An extensive list of Lemmy apps is available here:

LemmyApps.com

or lemmyapps.netlify.app


Visit our partner Communities!

Lemmy Plugins and Userscripts is a great place to enhance the Lemmy browsing experience. [email protected]

Lemmy Integrations is a community about all integrations with the lemmy API. Bots, Scripts, New Apps, etc. [email protected]

Lemmy Bots and Tools is a place to discuss and show off bots, tools, front ends, etc. you’re making that relate to lemmy. [email protected]

Lemmy App Development is a place for Lemmy builders to chat about building apps, clients, tools and bots for the Lemmy platform. [email protected]

founded 2 years ago
MODERATORS
 

hello! im developing lemmy client (on html5). i tried to do login function but... when i try to fetch /v3/user backend with auth-token it give me error:

{
  "error": "no_id_given"
}

but why? what im doing wrong? if you want here is my source file on github ( function: getLoggined() )

top 4 comments
sorted by: hot top controversial new old
[–] [email protected] 3 points 6 days ago* (last edited 6 days ago) (2 children)

To get the current logged-in user's details, that's actually retrieved from /api/v3/site for....reasons, I guess?

Your function can remain the same, but change the api endpoint to /site Also, the user details will be in the my_user key from get site response.

Is there a reason you're not using the lemmy-js-client? That will take care of a lot of the low-level fetching for you (and has TypeDocs which help you to know what response / form data is needed).

Your Original Function, Slightly Modified

 async function getLoggined() {
   try {
        const response = await fetch(`${api}/site`, {
            method: "GET",
            headers: {
                "Content-Type": "application/json",
                "Authorization": `Bearer ${lemmyToken}`
            }
        });
        alert(`Bearer ${lemmyToken}`);
        alert(await response.text());
        const data = await response.json();
        return data.my_user;
    } catch (error) {
        alert(`error while loading profile: ${error}`);
    }
}
[–] okelote360 2 points 5 days ago

thanks! it works!

[–] okelote360 0 points 5 days ago

i didnt use lemmy-js-client because i dont know how to install it in github pages...

[–] [email protected] 1 points 6 days ago

/api/v3/user is for fetching info about any user, it requires either a person_id or username to be given as a URL param to work, e.g. https://feddit.uk/api/v3/user?person_id=28426 will get my profile. There currently isn't a way to get just the person_view from the JWT, though API v4 will have an /account endpoint that you'll be able to GET with the auth header. Most apps GET the /site endpoint and use my_user returned from that.