# Laravel - How to programatically add user\_metadata and app\_metadata to a user?

**URL:** <https://community.auth0.com/t/laravel-how-to-programatically-add-user-metadata-and-app-metadata-to-a-user/44929>\
**Category:** Get Help\
**Tags:** laravel-6\
**Created:** [June 18, 2020, 4:19pm UTC](https://community.auth0.com/t/laravel-how-to-programatically-add-user-metadata-and-app-metadata-to-a-user/44929 "2020-06-18T16:19:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![roenfeldt](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/roenfeldt/32/19668_2.png) [@roenfeldt](https://community.auth0.com/u/roenfeldt)\
**Post date:** [June 18, 2020, 4:19pm UTC](https://community.auth0.com/t/laravel-how-to-programatically-add-user-metadata-and-app-metadata-to-a-user/44929/1 "2020-06-18T16:19:10Z")

</div>

Dear Auth0 Community,

I’m in need of guidance regarding enriching a user’s profile. I never expected such a trivial thing to be so complicated!

TL;DR: I followed the tutorial here [https://auth0.com/docs/quickstart/webapp/laravel/01-login](https://auth0.com/docs/quickstart/webapp/laravel/01-login) and now I have no idea of how to allow the logged-in users update their profile, by making use of standard claims, as well as custom claims. Moreover, I can’t understand how to programatically update the users’ app\_metadata.

Long(er) version: After three days of going back and forth through the Auth0 documentation, tutorials, as well as community posts, the only thing I was able to figure out, was that the user’s profile info can be fetched with `Auth0::getUser()['profile']`. Then I came across this thread [Easiest way to grab user\_metadata with Laravel SDK](http://community.auth0.com/t/easiest-way-to-grab-user-metadata-with-laravel-sdk/37327), which unfortunately didn’t really helped me understand the procedure of achieving my goal.

To conclude (with a question), is there any Laravel-based tutorial specifically made for beginners like me, that could at least point me into the right direction?

Many thanks.

---

<div class="post-metadata">

**Author:** ![James.Morrison](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/james.morrison/32/13507_2.png) [@James.Morrison](https://community.auth0.com/u/James.Morrison)\
**Post date:** [June 22, 2020, 2:06pm UTC](https://community.auth0.com/t/laravel-how-to-programatically-add-user-metadata-and-app-metadata-to-a-user/44929/2 "2020-06-22T14:06:55Z")

</div>

Hi there @roenfeldt and I hope you had a fantastic weekend!

> [@roenfeldt](#):
>
> To conclude (with a question), is there any Laravel-based tutorial specifically made for beginners like me, that could at least point me into the right direction?

As mentioned in the referenced post above I would point you towards building a [rule](https://auth0.com/docs/rules) that adds custom claims to one of your tokens, whether it be an ID token or Access token for the user attributes you’re looking for. I’ve shared a few docs below that dives into leveraging rules and how powerful they can be in your user workflow.

> **[Action Coding Guidelines](https://auth0.com/docs/customize/actions/action-coding-guidelines)**
>
> Write clear, concise, and secure Actions code with our coding guidelines.

> **[User Object Properties in Rules](https://auth0.com/docs/customize/rules/user-object-in-rules)**
>
> Describes the properties of the user object that stores information about the logged in user, returned by the identity provider.

However if there is a specific point that you are confused about, I would be happy to help!

---

<div class="post-metadata">

**Author:** ![roenfeldt](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/roenfeldt/32/19668_2.png) [@roenfeldt](https://community.auth0.com/u/roenfeldt)\
**Post date:** [June 27, 2020, 11:35am UTC](https://community.auth0.com/t/laravel-how-to-programatically-add-user-metadata-and-app-metadata-to-a-user/44929/4 "2020-06-27T11:35:05Z")

</div>

Hello @James.Morrison,

Thank you so much for your help. I finally understood the basics of implementing rules into the authentication workflow, and they indeed seem to be very powerful! I’m in the process of fine-tuning my first rule. I’m posting it here, in the hope that it’ll help someone else in the future.

Basically, I’m using this rule in order to redirect the **new** member to an `/onboarding` route. _ **New** _ is the keyword here, because I’m checking for their `given_name` custom claim property (which is initially empty in case of a Username-Password-Authentication signup), and redirect them accordingly to the “onboarding” route, where they’ll be able to fill in some mandatory fields, as well as some optional ones, should they choose to.

```auto
// Redirect to onboarding if new memebr
function (user, context, callback) {
    console.log(undefined === user.given_name);
    if (undefined === user.given_name) {
        context.redirect = {
            url: "http://laravel.test/onboarding"
        };
    }
    return callback(null, user, context);
}

```

---

<div class="post-metadata">

**Author:** ![roenfeldt](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/roenfeldt/32/19668_2.png) [@roenfeldt](https://community.auth0.com/u/roenfeldt)\
**Post date:** [June 29, 2020, 12:38pm UTC](https://community.auth0.com/t/laravel-how-to-programatically-add-user-metadata-and-app-metadata-to-a-user/44929/5 "2020-06-29T12:38:34Z")

</div>

Hello again @James.Morrison,

I just ran into a new issue that I simply cannot figure out. I’m hoping that you could clarify it for me.

My Laravel app is still based on the Auth0 tutorial here [Auth0 Laravel SDK Quickstarts: Login](https://auth0.com/docs/quickstart/webapp/laravel/01-login)

As I explained in my previous reply, I’m trying to offer the newly-registered member a way of enriching their profile by allowing them to fill out some personal data, as the next step either after signing up, or after logging in, in case they haven’t already filled up their `user.given_name` attribute.

In order to check if the user was successfully authenticated, I’m calling the `Auth::check()` method within the .blade file that’s connected in Laravel to the `/onboarding` route.

However, the user’s _ **authenticated** _ status returns `false` even after they’ve successfully authenticated, and were sent by the Auth0 rule towards the `/onboarding` route.

What’s the reason as to why the user’s authenticated status is wrongfully set to `false`?

I would highly appreciate your help figuring out a solution to this annoying problem.

Thank you.

---

<div class="post-metadata">

**Author:** ![James.Morrison](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/james.morrison/32/13507_2.png) [@James.Morrison](https://community.auth0.com/u/James.Morrison)\
**Post date:** [June 29, 2020, 2:49pm UTC](https://community.auth0.com/t/laravel-how-to-programatically-add-user-metadata-and-app-metadata-to-a-user/44929/6 "2020-06-29T14:49:29Z")

</div>

I would be happy to help on this front but to have a better idea of what’s going do you mind capturing a HAR file of the login event happening for a new test user and sending it over in a DM? Please be sure to select “Preserve log” to catch redirects and scrub the file of user passwords before passing, thanks!

> **[Generate and Analyze HAR Files](https://auth0.com/docs/troubleshoot/troubleshooting-tools/generate-and-analyze-har-files)**
>
> Learn how to troubleshoot with HAR files and steps to generate a HAR file.

---

<div class="post-metadata">

**Author:** ![roenfeldt](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/roenfeldt/32/19668_2.png) [@roenfeldt](https://community.auth0.com/u/roenfeldt)\
**Post date:** [June 29, 2020, 3:07pm UTC](https://community.auth0.com/t/laravel-how-to-programatically-add-user-metadata-and-app-metadata-to-a-user/44929/7 "2020-06-29T15:07:23Z")

</div>

Thanks for the fast reply! The thing is, I think I figured out the part where the authentication didn’t go through. Based on the Auth0 Docs information on **redirecting users from within rules** [Redirect Users from Within Rules](https://auth0.com/docs/rules/guides/redirect), my app was not sending the original `state` URL parameter and its value back to the /continue endpoint. I fixed that, and now my Laravel app shows that the user is indeed authenticated. However, now there’s one new issue. The rule doesn’t seem to be able to redirect the user to the /onboarding endpoint.

Should I go ahead with capturing a HAR file, as per your suggestion, or is there anything else I should do?

---

<div class="post-metadata">

**Author:** ![James.Morrison](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/james.morrison/32/13507_2.png) [@James.Morrison](https://community.auth0.com/u/James.Morrison)\
**Post date:** [July 14, 2020, 3:07pm UTC](https://community.auth0.com/t/laravel-how-to-programatically-add-user-metadata-and-app-metadata-to-a-user/44929/8 "2020-07-14T15:07:25Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
