-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
Added OAuth0 authentication support on the backend.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<template> | ||
<div class="main-layout"> | ||
<slot /> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
@import "assets/mixins"; | ||
.main-layout { | ||
@apply flex min-h-screen items-stretch relative; | ||
} | ||
</style> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { useNuxtApp, navigateTo } from "#app" | ||
|
||
export default defineNuxtRouteMiddleware(async (to, from) => { | ||
Check warning on line 3 in middleware/auth.global.ts
|
||
const app = useNuxtApp() | ||
const {localStorage} = window; | ||
|
||
if (!app.$appSettings.auth.enabled) { | ||
return; | ||
} | ||
|
||
// todo: move token to a store | ||
if (to.name !== 'login' && !app.$authToken.token) { | ||
return navigateTo('/login'); | ||
Check failure on line 13 in middleware/auth.global.ts
|
||
} | ||
|
||
if (to.name === 'login' && to?.query?.token) { | ||
localStorage?.setItem('token', to.query.token); | ||
// todo: use store | ||
app.$authToken.token = to.query.token; | ||
return navigateTo('/'); | ||
Check failure on line 20 in middleware/auth.global.ts
|
||
} | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<script setup lang="ts"> | ||
import { useNuxtApp, navigateTo } from "#app" | ||
Check failure on line 2 in pages/login.vue
|
||
import { REST_API_URL } from "~/src/shared/lib/io"; | ||
import { IconSvg } from "~/src/shared/ui"; | ||
definePageMeta({ | ||
Check failure on line 6 in pages/login.vue
|
||
layout: 'blank' | ||
}) | ||
const app = useNuxtApp() | ||
const redirect = async () => { | ||
await navigateTo(`${REST_API_URL}/${app.$appSettings.auth.login_url}`, { | ||
external: true | ||
}) | ||
} | ||
</script> | ||
|
||
<template> | ||
<div class="login-page"> | ||
<div class="login-form-container"> | ||
<IconSvg class="login-form--logo" name="logo"/> | ||
<div class="login-form"> | ||
<div class="login-form-left-block"> | ||
<h1 class="login-form--title">Welcome Back</h1> | ||
<p class="pb-2 text-center text-sm text-gray-800">Let's get you signed in.</p> | ||
<button class="login-form--button" @click="redirect"> | ||
<IconSvg class="w-6" name="lock" fill="currentcolor"/> | ||
Continue to SSO | ||
</button> | ||
</div> | ||
<div class="login-form-right-block" | ||
style="background: url('/bg.jpg'); background-size: cover; background-position: center center;"> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
|
||
<style lang="scss" scoped> | ||
@import "assets/mixins"; | ||
.login-page { | ||
@apply bg-gray-800; | ||
@apply h-screen w-screen; | ||
} | ||
.login-form-container { | ||
@apply flex flex-col items-center justify-center flex-1; | ||
@apply px-4 sm:px-0; | ||
@apply h-full; | ||
} | ||
.login-form { | ||
@apply flex w-full sm:w-3/4 md:w-2/3 xl:w-1/2 h-96; | ||
@apply shadow-2xl; | ||
@apply bg-gray-200; | ||
@apply rounded-2xl; | ||
@apply mt-10; | ||
} | ||
.login-form-left-block { | ||
@apply flex flex-col flex-1 justify-center items-center; | ||
@apply mb-8 p-12; | ||
@apply w-1/2; | ||
} | ||
.login-form-right-block { | ||
@apply w-0 md:w-1/2 h-full rounded-r-2xl; | ||
} | ||
.login-form--logo { | ||
@apply w-48 text-gray-200; | ||
} | ||
.login-form--title { | ||
@apply text-4xl text-center font-thin; | ||
@apply my-10; | ||
} | ||
.login-form--button { | ||
@apply bg-blue-500 hover:bg-blue-600 transition-colors; | ||
@apply text-white rounded; | ||
@apply px-4 py-2 gap-2; | ||
@apply inline-flex; | ||
} | ||
</style> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { useSettings } from "~/src/shared/lib/use-settings"; | ||
|
||
const {localStorage} = window; | ||
|
||
// todo: use store for token | ||
export default defineNuxtPlugin(async () => { | ||
const { | ||
api: {getSettings}, | ||
} = useSettings(); | ||
|
||
let settings = { | ||
auth: { | ||
enabled: false, | ||
login_url: '/login', | ||
}, | ||
version: '0.0.0', | ||
} | ||
|
||
try { | ||
settings = await getSettings() | ||
} catch (e) { | ||
console.error('Server is not available!') | ||
} | ||
|
||
if (!settings.auth.enabled) { | ||
return { | ||
provide: { | ||
authToken: {token: null}, | ||
appSettings: settings | ||
} | ||
} | ||
} | ||
|
||
const token: string | null = localStorage?.getItem('token') | ||
|
||
return { | ||
provide: { | ||
authToken: {token}, | ||
appSettings: settings | ||
} | ||
} | ||
}) |