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 ( {
@@ -26,41 +27,49 @@ export default defineNuxtConfig({
2627 global : true ,
2728 dirs : [ { path : '~/components' , prefix : 'tk' } ] ,
2829 } ,
29- modules : [ 'nuxt-api-party' , '@sidebase/nuxt-auth' , 'nuxt-quasar-ui' , '@vueuse/nuxt' , 'dayjs-nuxt' , ...extensions . appSetup . default ( ) ] ,
30- dayjs : {
31- locales : [ 'fr' ] ,
32- defaultLocale : 'fr' ,
33- } ,
30+ modules : [
31+ '@nuxt-alt/auth' ,
32+ '@nuxt-alt/http' ,
33+ '@pinia/nuxt' ,
34+ 'nuxt-quasar-ui' ,
35+ '@vueuse/nuxt' ,
36+ 'dayjs-nuxt' ,
37+ ...extensions . appSetup . default ( ) ,
38+ ] ,
3439 auth : {
35- baseURL : `${ TK_APP_API_URL } /core/auth` ,
36- provider : {
37- type : 'local' ,
38- endpoints : {
39- signIn : { path : '/login' , method : 'post' } ,
40- signOut : { path : '/logout' , method : 'post' } ,
41- signUp : { path : '/register' , method : 'post' } ,
42- getSession : { path : '/session' , method : 'get' } ,
43- } ,
44- pages : {
45- login : '/login' ,
46- } ,
47- } ,
48- session : {
49- enableRefreshOnWindowFocus : true ,
50- enableRefreshPeriodically : 5 * 60 * 1_000 ,
51- } ,
52- globalAppMiddleware : {
53- isEnabled : true ,
54- } ,
55- } ,
56- runtimeConfig : {
57- authJs : {
58- secret : TK_APP_AUTH_SECRET ,
59- } ,
60- public : {
61- authJs : {
62- // baseUrl: process.env.NUXT_NEXTAUTH_URL, // The URL of your deployed app (used for origin Check in production)
63- 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 : 60 * 5 ,
49+ } ,
50+ refreshToken : {
51+ property : 'refresh_token' ,
52+ data : 'refresh_token' ,
53+ maxAge : 60 * 60 * 4 ,
54+ } ,
55+ user : {
56+ property : 'user' ,
57+ autoFetch : true ,
58+ } ,
59+ clientId : false ,
60+ grantType : false ,
61+ endpoints : {
62+ login : { url : `${ TK_APP_API_URL } /core/auth/local` , method : 'post' , headers : { 'Content-Type' : 'application/json' } } ,
63+ refresh : { url : `${ TK_APP_API_URL } /core/auth/refresh` , method : 'post' , headers : { 'Content-Type' : 'application/json' } } ,
64+ logout : { url : `${ TK_APP_API_URL } /core/auth/logout` , method : 'post' } ,
65+ user : { url : `${ TK_APP_API_URL } /core/auth/session` , method : 'get' , propertyName : 'user' } ,
66+ } ,
67+ redirect : {
68+ logout : '/login' ,
69+ login : '/' ,
70+ } ,
71+ tokenType : 'Bearer' ,
72+ autoRefresh : true ,
6473 } ,
6574 } ,
6675 } ,
@@ -70,16 +79,6 @@ export default defineNuxtConfig({
7079 quasar : {
7180 iconSet : 'mdi-v5' ,
7281 } ,
73- apiParty : {
74- endpoints : {
75- api : {
76- url : TK_APP_API_URL ,
77- schema : `${ TK_APP_API_URL } /swagger/json` ,
78- cookies : true ,
79- } ,
80- } ,
81- allowClient : true ,
82- } ,
8382 vite : {
8483 define : {
8584 'process.env.DEBUG' : process . env . NODE_ENV === 'development' ,
@@ -100,4 +99,16 @@ export default defineNuxtConfig({
10099 // typeCheck: 'build,
101100 shim : false ,
102101 } ,
102+ hooks : {
103+ 'ready' : async ( ) => {
104+ console . log ( '[OpenapiTS] Generating .nuxt/types/service-api.d.ts...' )
105+ try {
106+ const fileData = await openapiTS ( `${ TK_APP_API_URL } /swagger/json` )
107+ writeFileSync ( '.nuxt/types/service-api.d.ts' , fileData )
108+ console . log ( '[OpenapiTS] Generated .nuxt/types/service-api.d.ts !' )
109+ } catch ( error ) {
110+ console . debug ( '[OpenapiTS] Error while generating .nuxt/types/service-api.d.ts' , error )
111+ }
112+ }
113+ }
103114} )
0 commit comments