@dargmuesli/nuxt-vio 14.0.1 → 14.0.3

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/.config/lint.js CHANGED
@@ -6,11 +6,12 @@ import eslintPluginCompat from 'eslint-plugin-compat'
6
6
  import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'
7
7
  import eslintPluginYml from 'eslint-plugin-yml'
8
8
  import globals from 'globals'
9
- import jiti from 'jiti'
9
+ import { createJiti } from 'jiti'
10
10
 
11
- const moduleFileUrl = new URL(import.meta.url)
12
- const JITI = jiti(moduleFileUrl.pathname)
13
- const POLYFILLS = JITI('../utils/constants.ts').POLYFILLS
11
+ const jiti = createJiti(import.meta.url)
12
+ const constants = await jiti.import('../utils/constants.ts')
13
+ // @ts-ignore
14
+ const POLYFILLS = constants.POLYFILLS
14
15
 
15
16
  const vueI18nConfiguration = vueI18n.configs['flat/recommended']
16
17
  const compatConfiguration = eslintPluginCompat.configs['flat/recommended']
@@ -1,5 +1,3 @@
1
- import { GTAG_COOKIE_ID } from '../utils/constants'
2
-
3
1
  export const useVioGtag = () => {
4
2
  const {
5
3
  gtag,
@@ -8,9 +6,27 @@ export const useVioGtag = () => {
8
6
  enableAnalytics,
9
7
  } = useGtag()
10
8
  const cookieControl = useCookieControl()
9
+ const updateConsent = ({ isGranted }: { isGranted: boolean }) => {
10
+ gtag('consent', 'update', {
11
+ // // the following are denied per default in the gtag module configuration
12
+ // ad_user_data: 'denied',
13
+ // ad_personalization: 'denied',
14
+ // ad_storage: 'denied',
15
+ analytics_storage: isGranted ? 'granted' : 'denied',
16
+ })
17
+ }
18
+ const enableGtag = () => {
19
+ updateConsent({ isGranted: true })
20
+ initializeGtag()
21
+ enableAnalytics()
22
+ }
23
+ const disableGtag = () => {
24
+ updateConsent({ isGranted: false })
25
+ disableAnalytics()
26
+ }
11
27
 
12
28
  if (cookieControl.cookiesEnabledIds.value?.includes(GTAG_COOKIE_ID)) {
13
- initializeGtag()
29
+ enableGtag()
14
30
  }
15
31
 
16
32
  watch(cookieControl.cookiesEnabledIds, (current, previous) => {
@@ -18,21 +34,14 @@ export const useVioGtag = () => {
18
34
  !previous?.includes(GTAG_COOKIE_ID) &&
19
35
  current?.includes(GTAG_COOKIE_ID)
20
36
  ) {
21
- gtag('consent', 'update', {
22
- ad_user_data: 'denied',
23
- ad_personalization: 'denied',
24
- ad_storage: 'denied',
25
- analytics_storage: 'granted',
26
- })
27
- initializeGtag()
28
- enableAnalytics()
37
+ enableGtag()
29
38
  }
30
39
 
31
40
  if (
32
41
  previous?.includes(GTAG_COOKIE_ID) &&
33
42
  !current?.includes(GTAG_COOKIE_ID)
34
43
  ) {
35
- disableAnalytics()
44
+ disableGtag()
36
45
  }
37
46
  })
38
47
  }
package/nuxt.config.ts CHANGED
@@ -104,6 +104,9 @@ export default defineNuxtConfig(
104
104
  },
105
105
  runtimeConfig: {
106
106
  public: {
107
+ i18n: {
108
+ baseUrl: SITE_URL,
109
+ },
107
110
  site: {
108
111
  url: SITE_URL,
109
112
  },
@@ -224,7 +227,6 @@ export default defineNuxtConfig(
224
227
  'frame-src': false as const,
225
228
  'img-src': false as const,
226
229
  'media-src': false as const,
227
- 'navigate-to': false as const,
228
230
  'object-src': false as const,
229
231
  'prefetch-src': false as const,
230
232
  'report-to': undefined,
@@ -293,9 +295,6 @@ export default defineNuxtConfig(
293
295
  $production: {
294
296
  runtimeConfig: {
295
297
  public: {
296
- i18n: {
297
- baseUrl: SITE_URL,
298
- },
299
298
  vio: {
300
299
  isInProduction: true,
301
300
  },
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "@nuxt/image": "1.8.0",
11
11
  "@nuxtjs/color-mode": "3.5.1",
12
12
  "@nuxtjs/html-validator": "1.8.2",
13
- "@nuxtjs/i18n": "8.3.0",
13
+ "@nuxtjs/i18n": "8.5.5",
14
14
  "@nuxtjs/seo": "2.0.0-rc.21",
15
15
  "@nuxtjs/tailwindcss": "6.12.1",
16
16
  "@pinia/nuxt": "0.5.4",
@@ -43,7 +43,7 @@
43
43
  "cookie-es": "1.2.2",
44
44
  "defu": "6.1.4",
45
45
  "h3": "1.12.0",
46
- "jiti": "1.21.6",
46
+ "jiti": "2.0.0",
47
47
  "lodash-es": "4.17.21",
48
48
  "nuxt": "3.13.2",
49
49
  "pinia": "2.2.2",
@@ -117,5 +117,5 @@
117
117
  "start:static": "serve .playground/.output/public --ssl-cert ./.config/certificates/ssl.crt --ssl-key ./.config/certificates/ssl.key"
118
118
  },
119
119
  "type": "module",
120
- "version": "14.0.1"
120
+ "version": "14.0.3"
121
121
  }
package/utils/auth.ts CHANGED
@@ -1,70 +1,65 @@
1
- import type { IncomingMessage, ServerResponse } from 'node:http'
2
-
1
+ import type { Client } from '@urql/vue'
3
2
  import { consola } from 'consola'
4
- import { parse, serialize } from 'cookie-es'
3
+ import { type H3Event, setCookie } from 'h3'
5
4
  import { decodeJwt } from 'jose'
6
- import type { Store } from 'pinia'
7
5
 
8
6
  import { useVioAuthStore } from '../store/auth'
9
7
  import { JWT_NAME } from './constants'
10
8
 
11
- export const getJwtFromCookie = ({ req }: { req: IncomingMessage }) => {
12
- if (req.headers.cookie) {
13
- const cookies = parse(req.headers.cookie)
9
+ export const getJwtFromCookie = () => {
10
+ const cookie = useCookie(JWT_NAME())
14
11
 
15
- if (cookies[JWT_NAME()]) {
16
- const cookie = decodeJwt(cookies[JWT_NAME()])
12
+ if (!cookie.value) {
13
+ consola.debug('No token cookie.')
14
+ return
15
+ }
17
16
 
18
- if (cookie.exp !== undefined && cookie.exp > Date.now() / 1000) {
19
- return {
20
- jwt: cookies[JWT_NAME()],
21
- jwtDecoded: cookie,
22
- }
23
- } else {
24
- consola.info('Token expired.')
25
- }
26
- } else {
27
- consola.debug('No token cookie.')
28
- }
29
- } else {
30
- consola.debug('No cookie header.')
17
+ const jwt = decodeJwt(cookie.value)
18
+
19
+ if (jwt.exp === undefined || jwt.exp <= Date.now() / 1000) {
20
+ consola.info('Token expired.')
21
+ return
22
+ }
23
+
24
+ return {
25
+ jwt: cookie.value,
26
+ jwtDecoded: jwt,
31
27
  }
32
28
  }
33
29
 
34
30
  export const jwtStore = async ({
35
31
  $urqlReset,
36
- store,
37
- res,
32
+ event,
33
+ isInProduction,
38
34
  jwt,
35
+ store,
39
36
  }: {
40
- $urqlReset: () => void
41
- store: Store
42
- res?: ServerResponse
37
+ $urqlReset: () => Client
38
+ event?: H3Event
39
+ isInProduction: boolean
43
40
  jwt?: string
41
+ store: ReturnType<typeof useVioAuthStore>
44
42
  }) => {
45
43
  $urqlReset()
46
44
 
47
45
  consola.trace('Storing the following JWT: ' + jwt)
48
- ;(store as unknown as { jwtSet: (jwtNew?: string) => void }).jwtSet(jwt)
46
+ store.jwtSet(jwt)
49
47
 
50
- if (import.meta.server) {
51
- res?.setHeader(
52
- 'Set-Cookie',
53
- serialize(JWT_NAME(), jwt || '', {
54
- expires: jwt ? new Date(Date.now() + 86400 * 1000 * 31) : new Date(0),
55
- httpOnly: true,
56
- path: '/',
57
- sameSite: 'lax', // Cannot be 'strict' to allow authentications after clicking on links within webmailers.
58
- secure: true,
59
- }),
60
- )
48
+ if (event) {
49
+ setCookie(event, JWT_NAME(), jwt || '', {
50
+ expires: jwt ? new Date(Date.now() + 86400 * 1000 * 31) : new Date(0),
51
+ httpOnly: true,
52
+ path: '/',
53
+ sameSite: 'lax', // Cannot be 'strict' to allow authentications after clicking on links within webmailers.
54
+ secure: isInProduction,
55
+ })
61
56
  } else {
62
57
  try {
63
58
  await $fetch('/api/auth', {
64
59
  method: 'POST',
65
60
  ...(jwt ? { headers: { Authorization: `Bearer ${jwt}` } } : {}),
66
61
  })
67
- } catch (error: unknown) {
62
+ } catch (error) {
68
63
  console.error(error)
69
64
  return Promise.reject(Error('Authentication api call failed.'))
70
65
  }
@@ -74,14 +69,16 @@ export const jwtStore = async ({
74
69
  export const useJwtStore = () => {
75
70
  const { $urqlReset, ssrContext } = useNuxtApp()
76
71
  const store = useVioAuthStore()
72
+ const runtimeConfig = useRuntimeConfig()
77
73
 
78
74
  return {
79
75
  async jwtStore(jwt?: string) {
80
76
  await jwtStore({
81
- $urqlReset: $urqlReset as () => void,
82
- store,
83
- res: ssrContext ? ssrContext.event.node.res : undefined,
77
+ $urqlReset: $urqlReset as () => Client,
78
+ event: ssrContext?.event,
79
+ isInProduction: runtimeConfig.public.vio.isInProduction,
84
80
  jwt,
81
+ store,
85
82
  })
86
83
  },
87
84
  }
@@ -89,27 +86,40 @@ export const useJwtStore = () => {
89
86
 
90
87
  export const signOut = async ({
91
88
  $urqlReset,
89
+ // client,
90
+ event,
91
+ isInProduction,
92
92
  store,
93
- res,
94
93
  }: {
95
- $urqlReset: () => void
96
- store: Store
97
- res?: ServerResponse
98
- }) => await jwtStore({ $urqlReset, store, res })
94
+ $urqlReset: () => Client
95
+ client: Client
96
+ event?: H3Event
97
+ isInProduction: boolean
98
+ store: ReturnType<typeof useVioAuthStore>
99
+ }) => {
100
+ await jwtStore({ $urqlReset, event, isInProduction, store })
101
+ // await authenticationAnonymous({
102
+ // $urqlReset,
103
+ // client,
104
+ // event,
105
+ // isInProduction,
106
+ // store,
107
+ // })
108
+ }
99
109
 
100
110
  export const useSignOut = () => {
101
- const { $urqlReset, ssrContext } = useNuxtApp()
111
+ const { $urql, $urqlReset, ssrContext } = useNuxtApp()
102
112
  const store = useVioAuthStore()
103
-
104
- if (typeof $urqlReset !== 'function')
105
- throw new Error('`$urqlReset` is not a function!')
113
+ const runtimeConfig = useRuntimeConfig()
106
114
 
107
115
  return {
108
116
  async signOut() {
109
117
  await signOut({
110
- $urqlReset: $urqlReset as () => void,
118
+ $urqlReset: $urqlReset as () => Client,
119
+ client: ($urql as Ref<Client>).value,
120
+ event: ssrContext?.event,
121
+ isInProduction: runtimeConfig.public.vio.isInProduction,
111
122
  store,
112
- res: ssrContext ? ssrContext.event.node.res : undefined,
113
123
  })
114
124
  },
115
125
  }
@@ -137,14 +137,14 @@ export const I18N_MODULE_CONFIG = {
137
137
  {
138
138
  code: 'en',
139
139
  file: 'en.json',
140
- name: 'English',
141
- iso: 'en', // Will be used as catchall locale by default.
140
+ language: 'en', // could be `en-US` is multiple `en` locales are differentiated
141
+ name: 'English', // Will be used as catchall locale by default.
142
142
  },
143
143
  {
144
144
  code: 'de',
145
145
  file: 'de.json',
146
+ language: 'de', // could be `de-DE` is multiple `de` locales are differentiated
146
147
  name: 'Deutsch',
147
- iso: 'de',
148
148
  },
149
149
  ],
150
150
  }