Skip to content

Commit

Permalink
chore: update react example
Browse files Browse the repository at this point in the history
  • Loading branch information
kangmingtay committed Mar 4, 2024
1 parent 525c008 commit 265c065
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
3 changes: 3 additions & 0 deletions example/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"react-scripts": "5.0.1",
"tailwindcss": "^1.8.10"
},
"devDependencies": {
"@babel/plugin-proposal-private-property-in-object": "^7.21.11"
},
"scripts": {
"build:tailwind": "tailwindcss build src/App.css -o src/tailwind.output.css",
"prestart": "npm run build:tailwind",
Expand Down
21 changes: 17 additions & 4 deletions example/react/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const supabaseURL = process.env.REACT_APP_SUPABASE_URL
const supabaseAnon = process.env.REACT_APP_SUPABASE_ANON_KEY

const auth = new AuthClient({
url: `${supabaseURL}/auth/v1`,
url: `${supabaseURL}`,
headers: {
accept: 'json',
apikey: supabaseAnon,
Expand Down Expand Up @@ -41,13 +41,11 @@ function App() {
console.log(event, session)
if (event === 'SIGNED_OUT' || event === 'SIGNED_IN') {
setSession(session)
window.location.reload()
}
})

return () => {
if (subscription) {
console.log('Subscription: ', subscription)
if (subscription.subscription) {
subscription.unsubscribe()
}
}
Expand Down Expand Up @@ -94,6 +92,10 @@ function App() {
let { error } = await auth.signOut()
if (error) console.log('Error: ', error)
}
async function handleSignInAnonymously(data) {
let { error } = await auth.signInAnonymously({ options: { data } })
if (error) alert(error.message)
}
async function forgotPassword() {
var email = prompt('Please enter your email:')
if (email === null || email === '') {
Expand Down Expand Up @@ -393,6 +395,17 @@ function App() {
</button>
</span>
</div>
<div className="mt-6">
<span className="block w-full rounded-md shadow-sm">
<button
onClick={() => handleSignInAnonymously({ color: 'blue' })}
type="button"
className="w-full flex justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-500 focus:outline-none focus:border-indigo-700 focus:shadow-outline-indigo active:bg-indigo-700 transition duration-150 ease-in-out"
>
Sign In Anonymously
</button>
</span>
</div>
</div>
</div>
</div>
Expand Down

0 comments on commit 265c065

Please sign in to comment.