Skip to content

Commit

Permalink
fix(router): dynamic auth redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
Novout committed May 21, 2022
1 parent abcf090 commit 74e5443
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
v-motion
:initial="{ opacity: 0, y: 50 }"
:enter="{ opacity: 1, y: 0, transition: { delay: 0 } }"
class="flex items-center flex-col w-full md:w-1/3 bg-black-opacity shadow-lg p-5"
class="flex items-center flex-col w-full md:w-3/5 xl:w-1/3 bg-black-opacity shadow-lg p-5"
>
<IconClose
class="absolute wb-icon right-5 w-6 h-6"
@click.prevent.stop="emit('close')"
/>
<img
v-motion
:initial="{ opacity: 0 }"
Expand Down Expand Up @@ -137,6 +141,7 @@
const supabase = useSupabase()
const router = useRouter()
const { t } = useI18n()
const emit = defineEmits(['close'])
const verification = ref<boolean>(false)
const user = reactive({
Expand Down
2 changes: 1 addition & 1 deletion packages/better-write-app/src/components/utils/Logo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
const onClick = () => {
if (props.hidden) return
local.onSaveProject().then(() => {
local.onSaveProject(false).then(() => {
props.back ? router.back() : router.push('/landing')
})
}
Expand Down
11 changes: 4 additions & 7 deletions packages/better-write-app/src/pages/Landing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@
class="flex text-gray-200 items-center text-lg rounded-full gap-2 transition-colors bg-gradient-to-br from-gray-300 to-gray-400 hover:from-gray-400 hover:to-gray-300 text-black px-7 py-3.5 md:(px-8 py-4) shadow-xl transition-colors font-bold"
@click.prevent.stop="router.push('/about')"
>
{{ t('landing.first.editor.about') }}
<p class="hidden md:inline-block">
{{ t('landing.first.editor.about') }}
</p>
<IconHelp class="w-6 h-6" />
</button>
<button
Expand Down Expand Up @@ -90,7 +92,7 @@
></v-typical>
</a>
</div>
<AuthMain v-else />
<AuthMain v-else @close="isNecessaryLogin = false" />
</div>
<div
v-else
Expand All @@ -114,20 +116,15 @@
import { useWebGL } from '@/use/webgl'
import { useI18n } from 'vue-i18n'
import { watch } from 'vue'
import { useAuthStore } from '@/store/auth'
import { useRouter } from 'vue-router'
const AUTH = useAuthStore()
const { onClick, isNecessaryLogin } = useLanding()
const { t } = useI18n()
const webgl = useWebGL()
const router = useRouter()
webgl.init()
if (AUTH.account.user) router.push('/')
watch(isNecessaryLogin, (login) => {
if (login) {
setTimeout(() => {
Expand Down
8 changes: 5 additions & 3 deletions packages/better-write-app/src/use/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useLocalStorage } from '@/use/storage/local'
import { useEventListener, useFullscreen, useNetwork } from '@vueuse/core'
import { useHead } from '@vueuse/head'
import { usePlugin } from 'better-write-plugin-core'
import { computed, onMounted, watch } from 'vue'
import { computed, onBeforeMount, onMounted, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import { useRouter } from 'vue-router'
import { useListener } from './listener'
Expand Down Expand Up @@ -39,11 +39,13 @@ export const useEditor = () => {
const network = useNetwork()

const init = () => {
onMounted(() => {
onBeforeMount(() => {
if (!AUTH.account.user && network.isOnline.value)
router.push({ path: '/landing', query: { login: 'auth' } })
})

project.onLoadProject()
onMounted(() => {
project.onLoadProject(undefined, false)
})

useEventListener('beforeunload', () => {
Expand Down

0 comments on commit 74e5443

Please sign in to comment.