Back

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

  • 1
  • Self Hosted
  • Auth
Carre
25 Jul, 2024, 15:58
TL;DR
Developers having issues adding labels to users in auth using User ID. The code seems fine but the label doesn't always update in Appwrite. Premium label works while lowercase "premium" does not. Console shows success but Appwrite doesn't update. Suggested to provide more details for better debugging. Use the server SDK for users functionality. Be cautious not to expose keys client-side. Difficulty tracing the cause of the irregular updates. Refreshing might temporarily resolve the issue.
Carre
25 Jul, 2024, 15:59

This didnt work either

Carre
25 Jul, 2024, 16:00

I have looked at https://appwrite.io/docs/products/auth/labels but cant solve it anyways

Carre
7 Aug, 2024, 19:08

Chrome

Joshi
7 Aug, 2024, 19:09

And that only happens to premium in lowercase?

Carre
7 Aug, 2024, 19:10

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"

Carre
7 Aug, 2024, 19:11

it only works then i change label to something totaly diffrent

Carre
7 Aug, 2024, 19:11

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

Carre
7 Aug, 2024, 19:12

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

Carre
7 Aug, 2024, 19:13

it is just like appwrite is glitching randomly

Joshi
7 Aug, 2024, 19:14

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

Joshi
7 Aug, 2024, 19:14

In bulletpoints

Joshi
7 Aug, 2024, 19:15

Because what you described sounds really weird

Carre
7 Aug, 2024, 19:15

yeah i know

Carre
7 Aug, 2024, 19:16

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> ); }

Carre
7 Aug, 2024, 19:17

and updateUserLabels.ts

Carre
7 Aug, 2024, 19:37

Can you show me how you have set up the structure? I give up on appwrite soon, the old database was so stright forward

Carre
7 Aug, 2024, 19:37

Really appreciate the effort and support anyways

Joshi
7 Aug, 2024, 19:43

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.

Steven
7 Aug, 2024, 20:54

What do you mean Appwrite don't update? So you:

  1. Went to the user in the Appwrite console
  2. Updated labels to be premium
  3. Clicked update
  4. Refreshed the page and...
Carre
8 Aug, 2024, 07:48

No i run the code to add label to the user i min auth. And after my server side console says that it worked, i go to appwrite and refresh the page, and sometimes there is no label added to the user/or the old label is still there.

Carre
8 Aug, 2024, 07:50

yeah i understand, sry that i cant provide more information

Joshi
8 Aug, 2024, 07:52

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

Joshi
8 Aug, 2024, 07:52

The one you sent in the chat?

Carre
8 Aug, 2024, 08:00

Now i got something intressting, look

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