)
@@ -271,7 +267,7 @@ Let's create a new component for that called `Account.js`.
import { useState, useEffect } from 'react'
import { supabase } from './supabaseClient'
-export default function Account({ session }) {
+const Account = ({ session }) => {
const [loading, setLoading] = useState(true)
const [username, setUsername] = useState(null)
const [website, setWebsite] = useState(null)
@@ -281,7 +277,7 @@ export default function Account({ session }) {
getProfile()
}, [session])
- async function getProfile() {
+ const getProfile = async () => {
try {
setLoading(true)
const user = supabase.auth.user()
@@ -308,7 +304,9 @@ export default function Account({ session }) {
}
}
- async function updateProfile({ username, website, avatar_url }) {
+ const updateProfile = async (e) => {
+ e.preventDefault()
+
try {
setLoading(true)
const user = supabase.auth.user()
@@ -336,52 +334,47 @@ export default function Account({ session }) {
}
return (
-
-
- Email
-
-
-
- Name
- setUsername(e.target.value)}
- />
-
-
- Website
- setWebsite(e.target.value)}
- />
-
-
-
- updateProfile({ username, website, avatar_url })}
- disabled={loading}
- >
- {loading ? 'Loading ...' : 'Update'}
-
-
-
-
- supabase.auth.signOut()}>
- Sign Out
-
-
+
+ {loading ? (
+ 'Saving ...'
+ ) : (
+
+ )}
+
supabase.auth.signOut()}>
+ Sign Out
+
)
}
+
+export default Account
```
-
-
### Launch!
Now that we have all the components in place, let's update `App.js`:
@@ -393,7 +386,7 @@ import { supabase } from './supabaseClient'
import Auth from './Auth'
import Account from './Account'
-export default function Home() {
+export default () => {
const [session, setSession] = useState(null)
useEffect(() => {
@@ -420,7 +413,6 @@ npm start
And then open the browser to [localhost:3000](http://localhost:3000) and you should see the completed app.
-

## Bonus: Profile photos
@@ -434,8 +426,9 @@ Let's create an avatar for the user so that they can upload a profile photo. We
```jsx title="src/Avatar.js"
import { useEffect, useState } from 'react'
import { supabase } from './supabaseClient'
+import VisuallyHidden from '@reach/visually-hidden'
-export default function Avatar({ url, size, onUpload }) {
+export default ({ url, size, onUpload }) => {
const [avatarUrl, setAvatarUrl] = useState(null)
const [uploading, setUploading] = useState(false)
@@ -443,7 +436,7 @@ export default function Avatar({ url, size, onUpload }) {
if (url) downloadImage(url)
}, [url])
- async function downloadImage(path) {
+ const downloadImage = async (path) => {
try {
const { data, error } = await supabase.storage.from('avatars').download(path)
if (error) {
@@ -456,8 +449,7 @@ export default function Avatar({ url, size, onUpload }) {
}
}
-
- async function uploadAvatar(event) {
+ const uploadAvatar = async (event) => {
try {
setUploading(true)
@@ -470,9 +462,7 @@ export default function Avatar({ url, size, onUpload }) {
const fileName = `${Math.random()}.${fileExt}`
const filePath = `${fileName}`
- let { error: uploadError } = await supabase.storage
- .from('avatars')
- .upload(filePath, file)
+ let { error: uploadError } = await supabase.storage.from('avatars').upload(filePath, file)
if (uploadError) {
throw uploadError
@@ -487,44 +477,36 @@ export default function Avatar({ url, size, onUpload }) {
}
return (
-
- {avatarUrl ? (
-
- ) : (
-
- )}
-
+
+
+ {uploading ? "Uploading..." : (
- {uploading ? 'Uploading ...' : 'Upload'}
+ Upload an avatar
-
-
+
+
+
+ )}
)
}
```
-
### Add the new widget
And then we can add the widget to the Account page:
-
```jsx title="src/Account.js"
// Import the new component
import Avatar from './Avatar'
@@ -545,7 +527,6 @@ return (
{/* ... */}
)
-
```
## Next steps
diff --git a/web/docs/guides/with-redwoodjs.mdx b/web/docs/guides/with-redwoodjs.mdx
index 9142e023bc3..3c2161bcb9e 100644
--- a/web/docs/guides/with-redwoodjs.mdx
+++ b/web/docs/guides/with-redwoodjs.mdx
@@ -38,7 +38,7 @@ Note: For RedwoodJS apps, port will be 8910
### GitHub
-If you get stuck at any point, take a look at [this repo](https://github.com/dthyresson/redwoodjs-supabase-quickstart).
+If you get stuck at any point, take a look at [this repo](https://github.com/redwoodjs/redwoodjs-supabase-quickstart).