Skip to content

Commit

Permalink
Basic user details are pulled into the template now
Browse files Browse the repository at this point in the history
  • Loading branch information
ramijames committed Nov 3, 2024
1 parent f1a1a64 commit 0a3919f
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 35 deletions.
4 changes: 2 additions & 2 deletions app.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<main>
<NuxtLayout>
<NuxtPage />
</main>
</NuxtLayout>
</template>
14 changes: 14 additions & 0 deletions assets/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,20 @@ button.blue,
}
}

button.clear,
.button.clear {
border: 1px solid rgba($white, 0.3);
background-color: rgba($blue, 0.05);
color: $white;
outline-color: rgba($white, 0.4);

&:hover {
border: 1px solid rgba($white, 1);
background-color: rgba($blue, 0.1);
outline: 4px solid rgba($white, 0.2);
}
}

button.green,
.button.green {
border: 1px solid rgba($mint-dark, 0.3);
Expand Down
41 changes: 41 additions & 0 deletions components/Navigation.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<template>
<nav class="max-width lg">
<section>
<span class="logo">Supabase Auth Example</span>
</section>
<section>
<button type="button" class="clear" @click="signOut">Log Out</button>
</section>
</nav>
</template>

<script setup>
const supabase = useSupabaseClient()
const user = useSupabaseUser()
const signOut = async () => {
const { error } = await supabase.auth.signOut()
if (error) console.log(error)
navigateTo('/login')
}
</script>

<style scoped lang="scss">
@use 'assets/variables' as *;
nav {
display: flex;
align-items: center;
justify-content: space-between;
padding: $spacing-sm $spacing-md;
background: rgba($brand, 1);
border-radius: $br-xxl;
color: $white;
position: sticky;
top: $spacing-md;
}
</style>
9 changes: 9 additions & 0 deletions layouts/auth.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<template>
<main>
<slot />
</main>
</template>

<script setup>
</script>
14 changes: 14 additions & 0 deletions layouts/default.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<template>
<main>
<Navigation />
<main>
<slot />
</main>
</main>
</template>

<script setup>
import Navigation from '~/components/Navigation.vue'
</script>
2 changes: 1 addition & 1 deletion middleware/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default defineNuxtRouteMiddleware(() => {
if (magiclink === true) {
return navigateTo("/confirm");
} else if (user.value) {
return navigateTo("/secure")
return navigateTo("/app")
}

})
45 changes: 45 additions & 0 deletions pages/app/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<template>
<main class="max-width lg">
<section id="UserDetails">
<h1>Hello!</h1>
<p>You are logged in with the email address, <i>{{ user.email }}</i>.</p>
<table>
<tr v-if="user.user_metadata.full_name">
<td>Display Name:</td>
<td>{{ user.user_metadata.full_name }}</td>
</tr>
<tr v-if="user.app_metadata.provider == 'github'">
<td>Github Avatar:</td>
<td><img :src="user.user_metadata.avatar_url" class="github-avatar" alt="Avatar" /></td>
</tr>
</table>
</section>
</main>
</template>

<script setup>
definePageMeta({
layout: 'default'
});
const user = useSupabaseUser()
</script>

<style scoped lang="scss">
@use 'assets/variables' as *;
#UserDetails {
padding: $spacing-lg;
.github-avatar {
width: 72px;
border-radius: $br-md;
border: $border;
}
}
</style>
2 changes: 1 addition & 1 deletion pages/confirm/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ watch(user, () => {
// Clear cookie
useCookie(`${cookieName}-redirect-path`).value = null
// Redirect to path
return navigateTo(redirectPath || '/secure');
return navigateTo(redirectPath || '/app');
}
}, { immediate: true })
</script>
15 changes: 0 additions & 15 deletions pages/index.vue

This file was deleted.

3 changes: 3 additions & 0 deletions pages/login/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@
definePageMeta({
middleware: ["auth"],
layout: "auth",
})
const loading = ref(false);
const notification = ref('');
const errorbox = ref('');
Expand Down
16 changes: 0 additions & 16 deletions pages/secure/index.vue

This file was deleted.

0 comments on commit 0a3919f

Please sign in to comment.