@d-mok/quasar-app-extension-quasar-axe 2.1.1 → 2.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// import {
|
|
2
|
+
// createClient,
|
|
3
|
+
// PostgrestError,
|
|
4
|
+
// SupabaseClient,
|
|
5
|
+
// Session,
|
|
6
|
+
// SupabaseClientOptions,
|
|
7
|
+
// } from '@supabase/supabase-js'
|
|
8
|
+
// import { qDialog } from './dialog'
|
|
9
|
+
|
|
10
|
+
// export type {
|
|
11
|
+
// PostgrestFilterBuilder,
|
|
12
|
+
// PostgrestSingleResponse,
|
|
13
|
+
// } from '@supabase/postgrest-js'
|
|
14
|
+
|
|
15
|
+
// class MySupabaseClient extends SupabaseClient {
|
|
16
|
+
// email: string = 'unauthenticated'
|
|
17
|
+
// session: Session | null = null
|
|
18
|
+
|
|
19
|
+
// constructor(
|
|
20
|
+
// supabaseUrl: string,
|
|
21
|
+
// supabaseKey: string,
|
|
22
|
+
// options?: SupabaseClientOptions<any>
|
|
23
|
+
// ) {
|
|
24
|
+
// super(supabaseUrl, supabaseKey, options)
|
|
25
|
+
// this.auth.onAuthStateChange((event, session) => {
|
|
26
|
+
// console.log('[SUPABASE AUTH]', event, session?.user?.email)
|
|
27
|
+
// this.session = session
|
|
28
|
+
// this.email = session?.user?.email ?? 'unauthenticated'
|
|
29
|
+
// })
|
|
30
|
+
// }
|
|
31
|
+
|
|
32
|
+
// async signIn() {
|
|
33
|
+
// await this.auth.signOut()
|
|
34
|
+
// await this.auth.signInWithOAuth({
|
|
35
|
+
// provider: 'google',
|
|
36
|
+
// options: {
|
|
37
|
+
// redirectTo: window.location.href,
|
|
38
|
+
// },
|
|
39
|
+
// })
|
|
40
|
+
// }
|
|
41
|
+
|
|
42
|
+
// async call<T>(fn: string, params?: object | undefined): Promise<T[]> {
|
|
43
|
+
// let { data, error } = await this.rpc<string, any>(fn, params)
|
|
44
|
+
// HANDLE_ERROR(data, error)
|
|
45
|
+
// return data
|
|
46
|
+
// }
|
|
47
|
+
|
|
48
|
+
// async callSingle<T>(fn: string, params?: object | undefined): Promise<T> {
|
|
49
|
+
// let { data, error } = await this.rpc<string, any>(fn, params).single()
|
|
50
|
+
// HANDLE_ERROR(data, error)
|
|
51
|
+
// return data as T
|
|
52
|
+
// }
|
|
53
|
+
|
|
54
|
+
// async waitForSignin(): Promise<void> {
|
|
55
|
+
// setInterval(() => {
|
|
56
|
+
// if (this.session === null) this.signIn()
|
|
57
|
+
// }, 1000)
|
|
58
|
+
// waitFor(
|
|
59
|
+
// () => this.session !== null,
|
|
60
|
+
// '[Wait for SignIn] waiting...',
|
|
61
|
+
// '[Wait for SignIn] DONE!'
|
|
62
|
+
// )
|
|
63
|
+
// }
|
|
64
|
+
// }
|
|
65
|
+
|
|
66
|
+
// export let supabase: MySupabaseClient
|
|
67
|
+
// let SUPABASE_URL = process.env.SUPABASE_URL
|
|
68
|
+
// let SUPABASE_KEY = process.env.SUPABASE_KEY
|
|
69
|
+
|
|
70
|
+
// if (SUPABASE_URL && SUPABASE_KEY) {
|
|
71
|
+
// supabase = new MySupabaseClient(SUPABASE_URL, SUPABASE_KEY, {
|
|
72
|
+
// auth: {
|
|
73
|
+
// autoRefreshToken: true,
|
|
74
|
+
// persistSession: true,
|
|
75
|
+
// detectSessionInUrl: true,
|
|
76
|
+
// },
|
|
77
|
+
// })
|
|
78
|
+
// }
|
|
79
|
+
|
|
80
|
+
// export function HANDLE_ERROR<T>(
|
|
81
|
+
// data: T[] | T | null,
|
|
82
|
+
// error: PostgrestError | null
|
|
83
|
+
// ): asserts data {
|
|
84
|
+
// if (error) {
|
|
85
|
+
// if (error.message === 'JWSError JWSInvalidSignature') {
|
|
86
|
+
// localStorage.removeItem('supabase.auth.token')
|
|
87
|
+
// qDialog.error(
|
|
88
|
+
// 'Database Error!',
|
|
89
|
+
// 'Your login session has expired. Please try refreshing the website.'
|
|
90
|
+
// )
|
|
91
|
+
// throw error
|
|
92
|
+
// }
|
|
93
|
+
// let msg = ''
|
|
94
|
+
// msg += error.details ?? '' + '<br/>'
|
|
95
|
+
// msg += error.message ?? '' + '<br/>'
|
|
96
|
+
// msg += error.hint ?? ''
|
|
97
|
+
// qDialog.error('Database Error!', msg)
|
|
98
|
+
// throw error
|
|
99
|
+
// }
|
|
100
|
+
// if (data === null) {
|
|
101
|
+
// qDialog.error('Supabase Error!', 'Returned data is null')
|
|
102
|
+
// throw 'supabase return data is null!'
|
|
103
|
+
// }
|
|
104
|
+
// }
|
|
105
|
+
|
|
106
|
+
// async function waitFor(
|
|
107
|
+
// predicate: () => boolean,
|
|
108
|
+
// waitingMsg: string,
|
|
109
|
+
// doneMsg: string
|
|
110
|
+
// ) {
|
|
111
|
+
// return new Promise(resolve => {
|
|
112
|
+
// async function checker() {
|
|
113
|
+
// if (predicate()) {
|
|
114
|
+
// console.log(doneMsg)
|
|
115
|
+
// resolve(true)
|
|
116
|
+
// } else {
|
|
117
|
+
// console.log(waitingMsg)
|
|
118
|
+
// setTimeout(checker, 50)
|
|
119
|
+
// }
|
|
120
|
+
// }
|
|
121
|
+
// checker()
|
|
122
|
+
// })
|
|
123
|
+
// }
|