Skip to content
Back

Trouble Retrieving Server-Side User Information After Client Login

  • 0
  • Web
Osmanlı
25 Feb, 2025, 10:15

Server: `import { Client, Account } from 'node-appwrite';

export default async function (req, res, log, error) { try {

TypeScript
const userClient = new Client()
    .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('xxx') // Your project ID
    .set(req.headers.authorization); // The user session to authenticate with

const account = new Account(userClient);

const result = await account.get();

res.status(200).json({ success: true });

} catch (err) { res.status(400).json({ success: false, error: e.message }); } }`

Client: ` const session = await account.getSession('current'); const jwt = await account.createJWT();

TypeScript
            const response = await functions.createExecution(
                '', // Function ID
                '', // Body (optional)
                false, // Async (optional)
                undefined, // Path (optional)
                ExecutionMethod.GET, // HTTP method (optional)
                { 'Authorization': `Bearer ${jwt.jwt}` }, // Headers (optional)
                undefined
            );`

Error: TypeError: Cannot read properties of undefined (reading 'status')

I want to retrieve the server-side information of a user who has logged in from the client and return it, but I'm having trouble doing so.

TL;DR
Developers are having trouble retrieving server-side user information after the client login due to errors with the `res.status()` method. The issue stems from incorrect usage of the method with response objects. The solution involves ensuring the `res` object is passed correctly and verifying code syntax. Proper code formatting is also advised.
ideclon
25 Feb, 2025, 10:20

FYI, it's best to wrap code in backticks to format a bit nicer. You can use 1 backtick for inline code (https://www.markdownguide.org/basic-syntax/#code) and 3 backticks for multiline code (https://www.markdownguide.org/extended-syntax/#syntax-highlighting).

ideclon
25 Feb, 2025, 10:21

Where did you get the Client()[…].set() syntax from?

ideclon
25 Feb, 2025, 10:21

The error seems to be on your res.status(…)

ideclon
25 Feb, 2025, 10:22

(i.e., .status() not being a valid method of res)

Osmanlı
25 Feb, 2025, 10:25

I need some more help with this. I checked if the res object is being passed correctly, but I'm still getting the same error. Could you help me with this?

ideclon
25 Feb, 2025, 10:27

You’ve confirmed that res.status() is a valid method? How did you do that?

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