-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
63 lines (56 loc) · 1.56 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import './css/style.css'
import './src/Log'
import createAuth0Client from '@auth0/auth0-spa-js'
import Footer from './src/components/Footer'
import Menu from './src/components/Menu'
import Home from './src/components/Home'
Mutable.component('menu', Menu)
Mutable.component('foot', Footer)
Mutable.component('home', Home)
const auth0 = await createAuth0Client({
domain: import.meta.env.VITE_AUTH0_DOMAIN,
client_id: import.meta.env.VITE_AUTH0_CLIENTID,
redirect_uri: window.location.origin,
})
new Mutable({
el: '#app',
data: {
is_auth: false,
site: {
title: 'Mampara',
description: 'Clon de Glassdoor criollo',
copyright: 'Pero más humilde y honesto. Por DevsChile. 💪',
},
user: {
name: '',
email: '',
},
},
methods: {
getParams: async function() {
const query = window.location.search
const shouldParseResult = query.includes("code=") && query.includes("state=")
if (shouldParseResult) {
await auth0.handleRedirectCallback()
window.history.replaceState({}, document.title, '/')
this.callMethod('isAuth', [])
}
},
isAuth: async function() {
const isAuthenticated = await auth0.isAuthenticated()
this.callMethod('getParams', [])
if (isAuthenticated) {
const userProfile = await auth0.getUser()
// set data
this.set('is_auth', true)
this.set('user.name', userProfile.name)
this.set('user.email', userProfile.email)
}
},
},
hooks: {
mounted() {
this.callMethod('isAuth', [])
}
}
})