Back

How to get user.$id from received token?

  • 0
  • Auth
Gigalink
13 Mar, 2024, 17:20

In firebase, from their firebase-admin sdk there is a way to get the user.uid from the token received (sent from front) obviously for security reasons to make sure users has right to access documents etc from server => how to do the same with node-appwrite?

TL;DR
Developers are trying to retrieve the user's ID from a token in a React Native app using Appwrite similar to how it's done in Firebase. To achieve this, they can create a client using the user session and then check if the user is authenticated using account.get(). This process involves setting up the client with the appropriate endpoint and project ID, then retrieving the session cookie from the request. They can use the session in their front-end application to get the user token for the current session.
Gigalink
13 Mar, 2024, 17:21

and as a matter of fact, from the front react-native-appwrite, how to get the user token for his current session?

Mr. Bakbuki
13 Mar, 2024, 17:22

You could create a client using the user session and check if they're authenticated using account.get()

TypeScript
const sessionClient = new Client()
    .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('<YOUR_PROJECT_ID>');            // Your project ID

const session = req.cookies.session; // Get the session cookie from the request
if (session) {
    sessionClient.setSession(session);
}

(this is from the ssr docs)

Gigalink
13 Mar, 2024, 17:50

this is all frontend though; and only tells me if I'm logged in etc, but I see no token information the kind of token we usually send inside the headers of a post to backend for security

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more