1
1
<script lang="ts" setup>
2
- import { NButton , NFlex } from ' naive-ui' ;
2
+ import { NButton , NCard , NCheckbox , NFlex , NH4 , NText } from ' naive-ui' ;
3
3
4
- import { onMounted , watch } from ' vue' ;
4
+ import { onMounted , ref , watch } from ' vue' ;
5
5
6
6
import { useRoute , useRouter } from ' vue-router' ;
7
7
8
8
import { TraktService } from ' ~/services/trakt.service' ;
9
9
import { useAuthSettingsStoreRefs } from ' ~/stores/settings/auth.store' ;
10
10
import { useI18n } from ' ~/utils' ;
11
11
12
- const i18n = useI18n (' global ' );
12
+ const i18n = useI18n (' login ' );
13
13
14
14
const route = useRoute ();
15
15
const router = useRouter ();
16
16
17
17
const { isAuthenticated } = useAuthSettingsStoreRefs ();
18
18
19
+ const onRedirect = (authenticated = isAuthenticated .value ) => {
20
+ if (! authenticated ) return ;
21
+ return router .push ((route .query .redirect as string ) ?? ' /' );
22
+ };
23
+
19
24
onMounted (() => {
25
+ onRedirect ();
20
26
watch (isAuthenticated , authenticated => {
21
- const { redirect } = route .query ;
22
- if (authenticated && redirect ) router .push (route .query .redirect as string );
27
+ onRedirect (authenticated );
23
28
});
24
29
});
25
30
26
- const onRedirect = async () => {
31
+ const signUp = ref (false );
32
+ const useSession = ref (false );
33
+
34
+ const onSignIn = async () => {
27
35
try {
28
- await TraktService .approve ();
36
+ await TraktService .approve ({
37
+ signup: signUp .value ,
38
+ prompt: ! useSession .value ,
39
+ });
29
40
} catch (error ) {
30
41
console .error (' Error:' , error );
31
42
}
@@ -34,15 +45,85 @@ const onRedirect = async () => {
34
45
35
46
<template >
36
47
<NFlex vertical justify =" space-around" align =" center" >
37
- <img alt =" Vue logo" class =" logo" src =" /assets/logo.svg" width =" 125" height =" 125" />
38
- <span >This is a login component</span >
39
- <NButton @click =" onRedirect" >Redirect Url</NButton >
48
+ <NCard class =" card" :title =" i18n('title')" hoverable >
49
+ <template #cover >
50
+ <div class =" spacer" />
51
+ <img
52
+ alt =" Vue logo"
53
+ class =" logo"
54
+ src =" /assets/logo.svg"
55
+ width =" 125"
56
+ height =" 125"
57
+ />
58
+ </template >
59
+
60
+ <NFlex vertical >
61
+ <NH4 class =" title" prefix =" bar" >{{ i18n('sub_title') }}</NH4 >
62
+
63
+ <NButton class =" button" @click =" onSignIn" >{{ i18n('sign_in') }}</NButton >
64
+
65
+ <NFlex class =" checkboxes" vertical >
66
+ <NCheckbox v-model:checked =" signUp" >
67
+ {{ i18n('checkbox__sign_up_for') }}
68
+ <NText type =" info" >{{ i18n('checkbox__new_account') }}</NText >
69
+ !
70
+ </NCheckbox >
71
+ <NCheckbox v-model:checked =" useSession" >
72
+ {{ i18n('checkbox__use') }}
73
+ <NText type =" info" >{{ i18n('checkbox__active_user') }}</NText >
74
+ {{ i18n('checkbox__session') }}
75
+ </NCheckbox >
76
+ </NFlex >
77
+ </NFlex >
78
+ </NCard >
40
79
</NFlex >
41
80
</template >
42
81
43
82
<style lang="scss" scoped>
44
- .logo {
45
- display : block ;
46
- margin : 2rem auto ;
83
+ @use ' src/styles/mixin' as mixin ;
84
+
85
+ .card {
86
+ @include mixin .hover-background ;
87
+
88
+ padding : 0 1.5rem ;
89
+
90
+ .spacer {
91
+ height : 60px ;
92
+ }
93
+
94
+ .logo {
95
+ position : absolute ;
96
+ top : -50px ;
97
+ left : 0 ;
98
+ }
99
+
100
+ :deep (.n-card-header ) {
101
+ font-size : 3em ;
102
+ text-align : center ;
103
+ }
104
+
105
+ .title {
106
+ margin : 0 ;
107
+ padding : 1rem ;
108
+ background : rgb (99 226 184 / 5% );
109
+ transition : background 0.5s ;
110
+ will-change : background ;
111
+ }
112
+
113
+ .button {
114
+ margin : 2rem ;
115
+ }
116
+
117
+ .checkboxes {
118
+ align-self : center ;
119
+ width : fit-content ;
120
+ margin-bottom : 1.5rem ;
121
+ }
122
+
123
+ & :hover {
124
+ .title {
125
+ background : rgb (99 226 184 / 9% );
126
+ }
127
+ }
47
128
}
48
129
</style >
0 commit comments