Forum Academy Marketplace Showcase Pricing Features

'Created by'-field ist empty, when login happens after 'Create a new thing'

Hi guys,

if a not-logged-in user creates a thing and a then tries to log in, the ‘created by’ field is NOT filled with the logged-in user. It stays empty.
However if the not-logged-in user creates a new thing and then tries to sign up, the ‘created by’ field IS filled with the newly signed user.
Does someone know why this happens?
Is there a way to set the ‘created by’ field, because our app uses that field.

Thanks in advance.

Yes, this is to be expected…

A non-logged in user isn’t recognised as a signed up user, and so is considered to be a new user even if they already have an account on your app (a new, temporary user object is created).

If they create a thing, that thing will be associated with that temporary user (although in the data-tab of your app you won’t see anything in the created by field, as they are not a signed up user).

If they then sign up and create an account, that temporary user now becomes a registered user, so you will see them as the creator of the thing they created earlier.

However, if the temporary use logs in (meaning they already have an account), then the current user changes from the temporary user to the existing user - meaning there’s no way to associate the two users, so you wouldn’t expect the thing they created to become associated with the existing user.

You can overcome this if you need to using your own cookies - simply store the newly created thing (unique id) in a cookie on the user’s browser, then when they log in you can check if they have any ‘things’ stored on their browser and, if they do associated that thing to them.

Note: you won’t be able to use the default ‘Created By’ field for this so you’ll need to add a custom User field to the datatype in question to associate it to the user (which is always a good idea anyway).

1 Like

This is incredible! I never thought of that. Here’s my question. What happens if:

Not-Logged-In user creates a thing > Refreshes the page or leaves the site > And then comes back?

@adamhholmes Do you have any resources on how to use cookies? (Please, don’t tell me javascript :slight_smile: )

@bubble52 I don’t know what’s your use case but the simplest solution I see is to remove “Created By” from the workflows. Instead create an “Owner” field to your User Datatype. Incorporate the Input Email in the form you make the Not-logged-in users fill. And use “Owner” in your workflows.

Actually something like this I had to implement just last week. Admin has the ability to create the user. And in such situations Created By used to be Admin’s email. So I’ve implemented the solution above. Hope this helps. Cheers.

Not-Logged-In user creates a thing > Refreshes the page or leaves the site > And then comes back?

Bubble stores a new temporary user for 3 days (using a cookie) so, unless the user has cookies disabled, and as long as they refresh and come back in the same browser, the user will be recognised for 3 days from the their visit. If they sign up within that time the temp user will be converted to a registered user, and the thing they created will remain associated with them.

If they don’t sign up within 3 days then the temp user is deleted, and a new temp user will be created if when they return (so the thing they created will not be associated with them after that).

Do you have any resources on how to use cookies?

There are several cookie plugins for Bubble (although I prefer to use the js-cookie API) - you can find them in the plugin marketplace (some are free, I think some are paid). (on a side note I’m kind of surprised Bubble doesn’t have cookie functionality built in, as it’s such a fundamental part of how websites work - maybe one day!..)

In terms of learning how to use cookies there are plenty of resources online, but this forum has many posts that are Bubble specific, so is a good place to start.

1 Like

Once again, thanks Adam!

1 Like

Thanks for the help.

This topic was automatically closed after 70 days. New replies are no longer allowed.