Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Update with-ionic-react.mdx to run in current verison (#36833)

Connor Molzfeb5a57b3227
diff --git a/apps/docs/content/guides/getting-started/tutorials/with-ionic-react.mdx b/apps/docs/content/guides/getting-started/tutorials/with-ionic-react.mdx
index 1eeafd56115..6d82cab6ac8 100644
--- a/apps/docs/content/guides/getting-started/tutorials/with-ionic-react.mdx
+++ b/apps/docs/content/guides/getting-started/tutorials/with-ionic-react.mdx
@@ -42,8 +42,8 @@ All we need are the API URL and the `anon` key that you copied [earlier](#get-th
<$CodeTabs>
```bash name=.env
-REACT_APP_SUPABASE_URL=YOUR_SUPABASE_URL
-REACT_APP_SUPABASE_ANON_KEY=YOUR_SUPABASE_ANON_KEY
+VITE_SUPABASE_URL=YOUR_SUPABASE_URL
+VITE_SUPABASE_ANON_KEY=YOUR_SUPABASE_ANON_KEY
```
</$CodeTabs>
@@ -53,11 +53,11 @@ on the browser, and that's completely fine since we have [Row Level Security](/d
<$CodeTabs>
-```js name=src/supabaseClient.js
+```js name=src/supabaseClient.ts
import { createClient } from '@supabase/supabase-js'
-const supabaseUrl = process.env.REACT_APP_SUPABASE_URL
-const supabaseAnonKey = process.env.REACT_APP_SUPABASE_ANON_KEY
+const supabaseUrl = import.meta.env.VITE_SUPABASE_URL || ''
+const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY || ''
export const supabase = createClient(supabaseUrl, supabaseAnonKey)
```
@@ -86,7 +86,8 @@ import {
useIonToast,
useIonLoading,
} from '@ionic/react';
-import { supabase } from '../supabaseClient';
+
+import {supabase} from '../supabaseClient'
export function LoginPage() {
const [email, setEmail] = useState('');
@@ -98,7 +99,9 @@ export function LoginPage() {
e.preventDefault();
await showLoading();
try {
- await supabase.auth.signIn({ email });
+ await supabase.auth.signInWithOtp({
+ "email": email
+ });
await showToast({ message: 'Check your email for the login link!' });
} catch (e: any) {
await showToast({ message: e.error_description || e.message , duration: 5000});
@@ -170,17 +173,29 @@ import {
} from '@ionic/react';
import { useEffect, useState } from 'react';
import { supabase } from '../supabaseClient';
+import { Session } from '@supabase/supabase-js';
export function AccountPage() {
const [showLoading, hideLoading] = useIonLoading();
const [showToast] = useIonToast();
- const [session] = useState(() => supabase.auth.session());
+ const [session, setSession] = useState<Session | null>(null)
const router = useIonRouter();
const [profile, setProfile] = useState({
username: '',
website: '',
avatar_url: '',
});
+
+ useEffect(() => {
+ const getSession = async () => {
+ setSession(await supabase.auth.getSession().then((res) => res.data.session))
+ }
+ getSession()
+ supabase.auth.onAuthStateChange((_event, session) => {
+ setSession(session)
+ })
+ }, [])
+
useEffect(() => {
getProfile();
}, [session]);
@@ -188,11 +203,11 @@ export function AccountPage() {
console.log('get');
await showLoading();
try {
- const user = supabase.auth.user();
+ const user = await supabase.auth.getUser();
const { data, error, status } = await supabase
.from('profiles')
.select(`username, website, avatar_url`)
- .eq('id', user!.id)
+ .eq('id', user!.data.user?.id)
.single();
if (error && status !== 406) {
@@ -223,18 +238,16 @@ export function AccountPage() {
await showLoading();
try {
- const user = supabase.auth.user();
+ const user = await supabase.auth.getUser();
const updates = {
- id: user!.id,
+ id: user!.data.user?.id,
...profile,
avatar_url: avatar_url,
updated_at: new Date(),
};
- const { error } = await supabase.from('profiles').upsert(updates, {
- returning: 'minimal', // Don't return the value after inserting
- });
+ const { error } = await supabase.from('profiles').upsert(updates);
if (error) {
throw error;
@@ -329,9 +342,12 @@ import { Session } from '@supabase/supabase-js'
setupIonicReact()
const App: React.FC = () => {
- const [session, setSession] = useState < Session > null
+ const [session, setSession] = useState<Session | null>(null)
useEffect(() => {
- setSession(supabase.auth.session())
+ const getSession = async () => {
+ setSession(await supabase.auth.getSession().then((res) => res.data.session))
+ }
+ getSession()
supabase.auth.onAuthStateChange((_event, session) => {
setSession(session)
})