#How can i add labels to users in auth, using User ID?

181 messages · Page 1 of 1 (latest)

analog summit
#

This didnt work either

analog summit
#

(HELP) How can i add labels to users in auth, using User ID?

peak karma
#

How can i add labels to users in auth, using User ID?

peak karma
peak karma
peak karma
analog summit
analog summit
gilded brook
#

Client SDK does not have "users"

#

You must use the server sdk

analog summit
analog summit
analog summit
#

I made a new sdk.ts like this and it worked once but is it any cooldowns or stuff with appwrite? Sometimes it don't add the label

peak karma
peak karma
#

so in your case, anyone can give themselves that premium label or remove labels or fetch everyone's user data

analog summit
analog summit
peak karma
analog summit
peak karma
analog summit
#

(all the client info is correct)

#

Why cant i just add "premium"?(admin and mvp works)

gilded brook
analog summit
#

if i totaly change the label and rerun it, it updates. If u just change 1 character or some it just keeps the old one

#

and i never get the premium label to apply

#

only "PREMIUM"

gilded brook
#

Can you try manually via Postman

analog summit
analog summit
gilded brook
#

What if you do it in the console?

#

It works for me in all cases and in the database it is also stored correctly.

analog summit
#

i only use Auth atm, removed it from db. Idk this error is so weird

#

The response also says that it has uppdated correctly and that the label is "premium" but appwrite auth is not uppdated

gilded brook
#

So we can at least single some causes out

analog summit
#

With Postman?

gilded brook
#

Console or/and Postman

analog summit
#

and its localhost

gilded brook
analog summit
#

the server side console

gilded brook
#

So it works as expected? But not if you do that via your frontend?

analog summit
#

the console works yes but appwrite don't update

#

that is the weird part, and i have zero errors

gilded brook
#

???

#

What is appwrite in this case?

analog summit
#

The Label in Auth dont update sometimes, even if the console says that is has updated

#

The console has always sad that is worked and the label updated to the new one, but in Auth label it only update sometimes

gilded brook
#

How do you determine that it has not updated?

analog summit
#

I refresh appwrite page and se if the new label is on the profile

gilded brook
#

appwrite page = appwrite console auth tab?

analog summit
#

I am on appwrite-auth and on my profile and looking at the label section

#

I refresh this side, and only sometimes it has been updated

gilded brook
#

Can you open try again in a new browser? Or private mode?

#

What browser is this?

analog summit
#

Chrome

gilded brook
#

And that only happens to premium in lowercase?

analog summit
#

i have never got "premium" to be applied. And it never works if you change the label to something similar as you had before, example "Sub" to "Subscription"

#

it only works then i change label to something totaly diffrent

#

and in the server console it always says that it worked and the new label is applied, but in reality, its not always applied

#

its so unpredictable and that is why i cant figure it out

#

it is just like appwrite is glitching randomly

gilded brook
#

Please provide a step by step guide where you are certain that this always happens

#

In bulletpoints

#

Because what you described sounds really weird

analog summit
#

this is my return/page.tsx either way.

import { stripe } from "../utils/stripe";
import { updateUserLabels } from "@/lib/updateUserLabels";

interface SearchParams {
session_id: string;
}

async function getSession(sessionId: string) {
const session = await stripe.checkout.sessions.retrieve(sessionId);
return session;
}

export default async function CheckoutReturn({ searchParams }: { searchParams: SearchParams }) {
const sessionId = searchParams.session_id;
const session = await getSession(sessionId);
const userId = session.client_reference_id;

console.log("Retrieved session:", session);

if (session?.payment_status === "paid" && userId) {
console.log("Payment is successful, updating user labels...");
await updateUserLabels(userId, 'premium');
} else {
console.log("Payment is not successful or user ID is missing.");
}

return (
<div className="flex items-center justify-center min-h-screen">
<div className="bg-white p-6 rounded-lg shadow-md w-full max-w-md text-center">
{session?.payment_status === "unpaid" ? (
<div>
<h2 className="text-2xl font-bold mb-4">Payment Failed</h2>
<p className="text-red-500">Payment did not work. Please try again.</p>
</div>
) : session?.payment_status === "paid" ? (
<div>
<h2 className="text-2xl font-bold mb-4">Thank You!</h2>
<p className="text-green-500">We appreciate your subscription!</p>
<p>Your Stripe customer ID is: <span className="font-mono">{session.customer as string}</span></p>
<p>Your User ID is: <span className="font-mono">{session.client_reference_id}</span></p>
</div>
) : (
<div>
<h2 className="text-2xl font-bold mb-4">Processing Payment</h2>
<p>Please wait while we process your payment.</p>
</div>
)}
</div>
</div>
);
}

#

and updateUserLabels.ts

analog summit
#

Really appreciate the effort and support anyways

gilded brook
#

In all honesty this is a really weird issue and I can't pinpoint where the issue is. Your code does not say say much nor does it look wrong on first glance. You have to provide as much information as possible in order to make debugging easier. I can't reproduce this on my end so you have to provide a step for step guide when this error happens.

peak karma
analog summit
analog summit
gilded brook
#

So to clarify. This only happens when you run "your" code?

#

The one you sent in the chat?

analog summit
#

Now i got something intressting, look

#

This is my console in vscode

#

And now i tryed something completly diffrent. And the label is uppdated

#

And now i try "premium" but it has not uppdated in appwrite

#
  • i dont even have admin label
#

maby the user has old labels that i cant see on appwrite website? is there any way to print all labels added to user?

gilded brook
#

Can you please log the response from users.get as well please

analog summit
#

It seems like that was the problem, i can see admin and premium label already

#

but i cant see it on appwrite website

#

can i clear all labels somehow?

gilded brook
#

lmao this is some weird shit

#

what sdk and skd version is this? let me check the source code of it real quick

analog summit
#

do updateLabels append the new label or removes all old and add one new?

gilded brook
#

Drop all the complexity and start a new project and just execute that flow without anything else

gilded brook
#

Like with all arrays in appwrite. In documents or user prefs

#

It always does a full update

analog summit
#

alright, idk why the admin label is there then

#

but this process works for you with appwrite?

gilded brook
#

Yes

#

There should not be admin in the first place when you never gave the user that value

gilded brook
analog summit
gilded brook
#

SDK is all good

#

Idk honestly

analog summit
#

yeah me neither. Will try the process with another account and se if admin label still is there, ik that on this account i have had admin label before

#

Alright, it works with premium on another account, where i got no labels before

analog summit
# gilded brook Idk honestly

can it has anything to do with my other appwrite.ts file where i createUsers and do all the other stuff? idk all have to be sdk or something

#

because i saw in the documentation create user with the sdk, but i dont use sdk when i create my users

gilded brook
#

You have to go through your whole code

#

I can't debug this for you

analog summit
#

I understand but do you know if i have to always use sdk?

gilded brook
#

I don't understand what you mean

#

How else would you like to interact with the API?

analog summit
#

i saw this in the documentation.

#

but i dont use sdk.

analog summit
# gilded brook I don't understand what you mean

Now i found something that could be the issue. When i log await users.get(userId) and have added "admin and mvp" on the website to the user, it still says in the console that the user dont have any labels, but the user information is correct. just like there is dual users with just diffrent labels. And i see one in appwrite and update one with the sdk.

#

I made this test.

#

just like the labels don't apply

#

and on the appwrite website i now got "admin" label, after all the code was compiled

#

just like something with appwrite is glitching

peak karma
#

Please share a screenshot of the full window, including the url in the browser address bar

peak karma
analog summit
#

Sometimes it updates the label to premium and sometimes not, but it always says that it successfully updated

#

this is the return/page.tsx part

#

And it always return succcess

#

this is the appwrite console url

peak karma
#

Do you have any call to update labels anywhere else?

analog summit
peak karma
analog summit
peak karma
analog summit
peak karma
analog summit
#

Yes but what do you mean with appwrite console then?

#

this page i suppose?

peak karma
analog summit
#

where can i find the "network request for the user and share the response"

peak karma
analog summit
#

the page don't fetch the user, it sends userId threw session

#

from the subscription page, to return page

peak karma
analog summit
#

Yes, and now?

analog summit
#

You mean this?

peak karma
peak karma
#

It would help to filter for fetch/xhr requests

analog summit
#

Yes i have done that

#

this is JSON in that response

peak karma
analog summit
#

this "account" response then?

peak karma
#

This is JSON, but it is not the user

peak karma
analog summit
peak karma
# analog summit

K now go through the flow in your app to update the labels to premium and then refresh the page in the Appwrite Console so you get this data again

analog summit
#

But it has been working sometimes before and all suddenly it just stops to work

#

4 in a row is record anyways

#

And now i only worked 1 time on the macbook, the 2th time it didnt update.

peak karma
analog summit