1
+ import { useApiStore } from '@/stores/api'
1
2
import { useCameraStore } from '@/stores/camera'
2
3
import { mande } from 'mande'
3
4
import { defineStore } from 'pinia'
@@ -9,7 +10,7 @@ export const useProcessDeviceStore = defineStore('processDevice', () => {
9
10
const message = ref ( '' )
10
11
const showSuccess = ref ( false )
11
12
const showError = ref ( false )
12
-
13
+ const apiStore = useApiStore ( )
13
14
function $reset ( ) {
14
15
message . value = ''
15
16
showSuccess . value = false
@@ -43,13 +44,10 @@ export const useProcessDeviceStore = defineStore('processDevice', () => {
43
44
async function authDevice ( val ) {
44
45
try {
45
46
const qrData = JSON . parse ( val )
46
- console . log ( qrData )
47
47
if ( qrData . handshake_version > 1 ) {
48
48
message . value = 'Unsupported handshake version'
49
49
showErrorMsg ( )
50
50
return
51
- } else {
52
- console . log ( 'Handshake version is 1' )
53
51
}
54
52
55
53
const payload = {
@@ -62,28 +60,24 @@ export const useProcessDeviceStore = defineStore('processDevice', () => {
62
60
software_version : 'x.x'
63
61
}
64
62
let url = qrData . url
63
+ const port = import . meta. env . VITE_LOCAL_PORT || 3000
65
64
if ( url . includes ( 'localhost' ) ) {
66
- url = `${ url } :8000 ` // Add your desired port number here
65
+ url = `${ url } :${ port } ` // Add your desired port number here
67
66
}
68
- console . log ( url )
69
67
const api = mande ( url , { headers : { 'Content-Type' : 'application/json' } } )
70
68
const response = await api . post ( '/api/v1/device/initialize' , payload )
71
- console . log ( response )
72
69
if ( response ) {
70
+ apiStore . newSession ( true )
73
71
const data = response
74
- console . log ( data . api_token )
75
72
localStorage . setItem ( 'api_token' , data . api_token )
76
73
localStorage . setItem ( 'organizer' , data . organizer )
77
74
localStorage . setItem ( 'url' , url )
78
- router . push ( { name : 'eventyayevents ' } )
75
+ router . push ( { name : 'eventyayselect ' } )
79
76
showSuccessMsg ( )
80
77
} else {
81
- console . log ( 'Something happend' )
82
78
showErrorMsg ( )
83
79
}
84
80
} catch ( error ) {
85
- console . log ( error )
86
- console . log ( 'Error in catch' )
87
81
showErrorMsg ( )
88
82
}
89
83
}
0 commit comments