Simplify everything to match supabase example and also downgrade supabase

This commit is contained in:
Michael Dausmann
2023-01-28 11:01:57 +11:00
parent edd65f1301
commit d19b713f25
11 changed files with 2034 additions and 1504 deletions

7
app.vue Normal file
View File

@@ -0,0 +1,7 @@
<template>
<div>
<AppHeader />
<NuxtPage />
<AppFooter />
</div>
</template>

5
components/AppFooter.vue Normal file
View File

@@ -0,0 +1,5 @@
<template>
<div>
<h3>Nuxt 3 Boilerplate - AppFooter</h3>
</div>
</template>

19
components/AppHeader.vue Normal file
View File

@@ -0,0 +1,19 @@
<script setup lang="ts">
console.log('AppHeader.vuew - setup script');
const supabase = useSupabaseClient();
const user = useSupabaseUser();
async function signout() {
await supabase.auth.signOut();
navigateTo('/', {replace: true});
}
</script>
<template>
<div>
<h3>Nuxt 3 Boilerplate - AppHeader</h3>
<div v-if="user">logged in as: {{ user.email }}: <button @click="signout()">Sign Out</button></div>
<div v-if="!user">Not Logged in</div>
<hr>
</div>
</template>

View File

@@ -1,22 +0,0 @@
<script setup lang="ts">
const supabase = useSupabaseAuthClient();
const user = await useSupabaseUser();
const email = (user.value)?user.value.email:null;
async function signout() {
const { error } = await supabase.auth.signOut()
navigateTo('/');
}
</script>
<template>
<div>
<h3>Authenticated Header</h3>
<div v-if="email">logged in as: {{ email }}: <button @click="signout()">Sign Out</button></div>
<div v-if="!email">Not Logged in</div>
<hr>
<slot />
<hr>
<h4>Authenticated Footer</h4>
</div>
</template>

View File

@@ -1,9 +0,0 @@
<template>
<div>
<h3>Default Header</h3>
<hr>
<slot />
<hr>
<h4>Default Footer</h4>
</div>
</template>

View File

@@ -1,6 +1,7 @@
export default defineNuxtRouteMiddleware((to) => { export default defineNuxtRouteMiddleware(() => {
const user = useSupabaseUser(); const user = useSupabaseUser()
if(!user.value && to.path === '/dashboard'){
navigateTo('login'); if (!user.value) {
} return navigateTo('/')
}
}) })

3416
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -8,9 +8,9 @@
"postinstall": "nuxt prepare" "postinstall": "nuxt prepare"
}, },
"devDependencies": { "devDependencies": {
"nuxt": "3.0.0" "nuxt": "^3.1.1"
}, },
"dependencies": { "dependencies": {
"@nuxtjs/supabase": "^0.3.0" "@nuxtjs/supabase": "^0.2.0-7"
} }
} }

View File

@@ -1,11 +1,12 @@
<script setup lang="ts"> <script setup lang="ts">
const user = await useSupabaseUser();
definePageMeta({ definePageMeta({
middleware: ['auth'], middleware: ['auth'],
layout: "authenticated",
}); });
</script> </script>
<template> <template>
<div> <div>
<h3>Dashboard</h3> <h3>{{ user?.user_metadata.full_name }}'s Dashboard</h3>
<div>Stuff</div>
</div> </div>
</template> </template>

View File

@@ -1,17 +1,15 @@
<script setup lang="ts"> <script setup lang="ts">
definePageMeta({ const user = useSupabaseUser()
middleware: ['auth'], const supabase = useSupabaseClient();
}); watchEffect(() => {
if (user.value) {
//horrible horrible kludge from https://github.com/nuxt-modules/supabase/issues/28#issuecomment-1353070523 navigateTo('/dashboard', {replace: true})
const user = useSupabaseUser(); }
watchEffect(async () => { })
if (user.value) await navigateTo("dashboard");
});
</script> </script>
<template> <template>
<div> <div>
<h3>Index</h3> <h3>Index</h3>
<NuxtLink to="/login">Login</NuxtLink> <button @click="supabase.auth.signInWithOAuth({provider: 'google'})">Sign In with Google</button>
</div> </div>
</template> </template>

View File

@@ -1,22 +0,0 @@
<script setup lang="ts">
definePageMeta({
middleware: ['auth'],
});
const supabase = useSupabaseAuthClient();
async function signInWithGoogle() {
const { data, error } = await supabase.auth.signInWithOAuth({
provider: 'google',
// options: { redirectTo: 'dashboard'} // the redirectTo option doesn't work
})
// navigateTo('dashboard'); // This doesn't work, it navigates prior to the oauth handshake completing and then the handshake lands on the index page and ignores the middleware.
}
</script>
<template>
<div>
Login
<button @click="signInWithGoogle()">Sign In with Google</button>
</div>
</template>