11import { extensions } from '@libertech-fr/teaket_common'
22import pugPlugin from 'vite-plugin-pug'
3- import { resolve } from 'node:path'
3+ import openapiTS from 'openapi-typescript'
4+ import { writeFileSync } from 'fs'
5+ import { resolve } from 'path'
46
57const TK_APP_API_URL = process . env . TK_APP_API_URL || 'http://localhost:7100'
6- const TK_APP_AUTH_SECRET = process . env . TK_APP_AUTH_SECRET
78
89// https://nuxt.com/docs/api/configuration/nuxt-config
910export default defineNuxtConfig ( {
@@ -21,65 +22,63 @@ export default defineNuxtConfig({
2122 enabled : true ,
2223 } ,
2324 } ,
24- plugins : [
25- { src : '~/plugins/ofetch' } ,
26- ] ,
25+ plugins : [ { src : '~/plugins/ofetch' } ] ,
2726 components : {
2827 global : true ,
2928 dirs : [ { path : '~/components' , prefix : 'tk' } ] ,
3029 } ,
3130 modules : [
32- 'nuxt-api-party' ,
33- '@sidebase/nuxt-auth' ,
31+ '@nuxt-alt/auth' ,
32+ '@nuxt-alt/http' ,
33+ '@pinia/nuxt' ,
3434 'nuxt-quasar-ui' ,
35+ '@vueuse/nuxt' ,
36+ 'dayjs-nuxt' ,
3537 ...extensions . appSetup . default ( ) ,
3638 ] ,
3739 auth : {
38- baseURL : `${ TK_APP_API_URL } /core/auth` ,
39- provider : {
40- type : 'local' ,
41- endpoints : {
42- signIn : { path : '/login' , method : 'post' } ,
43- signOut : { path : '/logout' , method : 'post' } ,
44- signUp : { path : '/register' , method : 'post' } ,
45- getSession : { path : '/session' , method : 'get' } ,
46- } ,
47- pages : {
48- login : '/login' ,
49- } ,
50- } ,
51- session : {
52- enableRefreshOnWindowFocus : true ,
53- enableRefreshPeriodically : 5 * 60 * 1_000 ,
54- } ,
55- globalAppMiddleware : {
56- isEnabled : true ,
57- } ,
58- } ,
59- runtimeConfig : {
60- authJs : {
61- secret : TK_APP_AUTH_SECRET ,
62- } ,
63- public : {
64- authJs : {
65- // baseUrl: process.env.NUXT_NEXTAUTH_URL, // The URL of your deployed app (used for origin Check in production)
66- verifyClientOnEveryRequest : true , // whether to hit the /auth/session endpoint on every client request
40+ globalMiddleware : true ,
41+ rewriteRedirects : true ,
42+ watchLoggedIn : true ,
43+ strategies : {
44+ local : {
45+ scheme : 'refresh' ,
46+ token : {
47+ property : 'access_token' ,
48+ maxAge : 1 * 5 ,
49+ // maxAge: 60 * 5,
50+ } ,
51+ refreshToken : {
52+ property : 'refresh_token' ,
53+ data : 'refresh_token' ,
54+ maxAge : 60 * 60 * 4 ,
55+ } ,
56+ user : {
57+ property : 'user' ,
58+ autoFetch : true ,
59+ } ,
60+ clientId : false ,
61+ grantType : false ,
62+ endpoints : {
63+ login : { url : `${ TK_APP_API_URL } /core/auth/local` , method : 'post' , headers : { 'Content-Type' : 'application/json' } } ,
64+ refresh : { url : `${ TK_APP_API_URL } /core/auth/refresh` , method : 'post' , headers : { 'Content-Type' : 'application/json' } } ,
65+ logout : { url : `${ TK_APP_API_URL } /core/auth/logout` , method : 'post' } ,
66+ user : { url : `${ TK_APP_API_URL } /core/auth/session` , method : 'get' , propertyName : 'user' } ,
67+ } ,
68+ redirect : {
69+ logout : '/login' ,
70+ login : '/' ,
71+ } ,
72+ tokenType : 'Bearer' ,
73+ autoRefresh : true ,
6774 } ,
6875 } ,
6976 } ,
7077 appConfig : {
7178 customSlots : { } ,
7279 } ,
73- quasar : { } ,
74- apiParty : {
75- endpoints : {
76- api : {
77- url : TK_APP_API_URL ,
78- schema : `${ TK_APP_API_URL } /swagger/json` ,
79- cookies : true ,
80- } ,
81- } ,
82- allowClient : true ,
80+ quasar : {
81+ iconSet : 'mdi-v5' ,
8382 } ,
8483 vite : {
8584 define : {
@@ -101,4 +100,16 @@ export default defineNuxtConfig({
101100 // typeCheck: 'build,
102101 shim : false ,
103102 } ,
103+ hooks : {
104+ 'ready' : async ( ) => {
105+ console . log ( '[OpenapiTS] Generating .nuxt/types/service-api.d.ts...' )
106+ try {
107+ const fileData = await openapiTS ( `${ TK_APP_API_URL } /swagger/json` )
108+ writeFileSync ( '.nuxt/types/service-api.d.ts' , fileData )
109+ console . log ( '[OpenapiTS] Generated .nuxt/types/service-api.d.ts !' )
110+ } catch ( error ) {
111+ console . debug ( '[OpenapiTS] Error while generating .nuxt/types/service-api.d.ts' , error )
112+ }
113+ }
114+ }
104115} )
0 commit comments