Help needed with dbAuth

I am now working on a simple blog using dbAuth and local db.
simple-redwood-blog

When I create post in admin/PostForm, I cannot get the currentUser details(eg. email) but it works normally in layout.

// simple-blog\web\src\components\Blog\Post\Posts\Posts.js

<TextField
  name="author"
  defaultValue={( props.post?.author ? props.post?.author : currentUser.email )}
  className="rw-input"
  errorClassName="rw-input rw-input-error"
  validation={{ required: true }}
/>
// redwood-tutorial\web\src\layouts\BlogLayout\BlogLayout.js

 <li>
  {isAuthenticated ? (
    <div>
      <button type="button" onClick={logOut} className="py-2 px-4">
        Logout
      </button>
    </div>
  ) : (
      <Link to={routes.login()} className="py-2 px-4">
        Login
      </Link>
    )}
</li>
{isAuthenticated && (
  <div className="absolute bottom-1 right-0 mr-12 text-xs text-blue-300">
    {currentUser.email}
  </div>
)}

I can only get the value of currentUser.id. How to get more user metadata?

Take a look in api/src/lib/auth.js for the getCurrentUser() function. It lists what fields are included in currentUser. Make sure you don’t add hashedPassword or salt to that list! :slight_smile:

Thanks a lot. I found getCurrentUser() function.

If there is an avatar field in User Model,
Should I stored it as base64 or an image link?
Which one will be better if I need to call this field in Cell?

If you have a user’s email, you can hash it to return their Gravatar which is a nice option where you don’t need any file storage.

See Gravatar - Globally Recognized Avatars

Since I often use Supabase as my Postgres database. I also use their storage feature

And upload from the web side directly to that and then store the url on the user’s profile record.

1 Like

Using their Gravatar is a great option! If you really want to let them upload their own, but aren’t using Supabase, we have a how-to article on file uploads with Filestack: https://redwoodjs.com/docs/how-to/file-uploads

2 Likes

Thanks! I think filestack would be better for this blog since filestack-react provided an upload component for me.

Supabase is great. It is similar to AWS S3 bucket. I will try it in next project.