subaya 1.0.1 → 1.0.2
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/dist/commands/axios/AxiosGeneratorCommand.d.ts.map +1 -1
- package/dist/commands/axios/AxiosGeneratorCommand.js +97 -17
- package/dist/commands/axios/AxiosGeneratorCommand.js.map +1 -1
- package/dist/commands/provider/ProviderGeneratorCommand.d.ts +2 -1
- package/dist/commands/provider/ProviderGeneratorCommand.d.ts.map +1 -1
- package/dist/commands/provider/ProviderGeneratorCommand.js.map +1 -1
- package/dist/commands/route/NextRouteGeneratorCommand.js +1 -1
- package/dist/commands/route/NextRouteGeneratorCommand.js.map +1 -1
- package/dist/commands/supabase/SupabaseCommand.d.ts +2 -1
- package/dist/commands/supabase/SupabaseCommand.d.ts.map +1 -1
- package/dist/commands/supabase/SupabaseCommand.js +97 -25
- package/dist/commands/supabase/SupabaseCommand.js.map +1 -1
- package/dist/core/EnsureSystem.d.ts +3 -0
- package/dist/core/EnsureSystem.d.ts.map +1 -1
- package/dist/core/EnsureSystem.js +16 -0
- package/dist/core/EnsureSystem.js.map +1 -1
- package/dist/core/FileSystemService.d.ts +1 -1
- package/dist/core/FileSystemService.d.ts.map +1 -1
- package/dist/core/FileSystemService.js +8 -0
- package/dist/core/FileSystemService.js.map +1 -1
- package/dist/template/axios/instance.d.ts +3 -1
- package/dist/template/axios/instance.d.ts.map +1 -1
- package/dist/template/axios/instance.js +204 -19
- package/dist/template/axios/instance.js.map +1 -1
- package/dist/template/axios/nextServerJwt.d.ts +4 -0
- package/dist/template/axios/nextServerJwt.d.ts.map +1 -0
- package/dist/template/axios/nextServerJwt.js +60 -0
- package/dist/template/axios/nextServerJwt.js.map +1 -0
- package/dist/template/axios/protectedProxy.d.ts +2 -0
- package/dist/template/axios/protectedProxy.d.ts.map +1 -0
- package/dist/template/axios/protectedProxy.js +40 -0
- package/dist/template/axios/protectedProxy.js.map +1 -0
- package/dist/template/axios/useLoginHook.d.ts +2 -0
- package/dist/template/axios/useLoginHook.d.ts.map +1 -0
- package/dist/template/axios/useLoginHook.js +16 -0
- package/dist/template/axios/useLoginHook.js.map +1 -0
- package/dist/template/axios/useLogoutHook.d.ts +2 -0
- package/dist/template/axios/useLogoutHook.d.ts.map +1 -0
- package/dist/template/axios/useLogoutHook.js +15 -0
- package/dist/template/axios/useLogoutHook.js.map +1 -0
- package/dist/template/axios/utilJwt.d.ts +2 -0
- package/dist/template/axios/utilJwt.d.ts.map +1 -0
- package/dist/template/axios/utilJwt.js +52 -0
- package/dist/template/axios/utilJwt.js.map +1 -0
- package/dist/template/supabase/actions/auth.d.ts +2 -0
- package/dist/template/supabase/actions/auth.d.ts.map +1 -0
- package/dist/template/supabase/actions/auth.js +61 -0
- package/dist/template/supabase/actions/auth.js.map +1 -0
- package/dist/template/supabase/actions/crud.d.ts +3 -0
- package/dist/template/supabase/actions/crud.d.ts.map +1 -0
- package/dist/template/supabase/actions/crud.js +72 -0
- package/dist/template/supabase/actions/crud.js.map +1 -0
- package/dist/template/supabase/actions/user.d.ts +2 -0
- package/dist/template/supabase/actions/user.d.ts.map +1 -0
- package/dist/template/supabase/actions/user.js +36 -0
- package/dist/template/supabase/actions/user.js.map +1 -0
- package/dist/template/supabase/admin/supabaseAdminLayout.d.ts +2 -0
- package/dist/template/supabase/admin/supabaseAdminLayout.d.ts.map +1 -0
- package/dist/template/supabase/admin/supabaseAdminLayout.js +7 -0
- package/dist/template/supabase/admin/supabaseAdminLayout.js.map +1 -0
- package/dist/template/supabase/admin/supabaseAdminLoginLayout.d.ts +2 -0
- package/dist/template/supabase/admin/supabaseAdminLoginLayout.d.ts.map +1 -0
- package/dist/template/supabase/admin/supabaseAdminLoginLayout.js +114 -0
- package/dist/template/supabase/admin/supabaseAdminLoginLayout.js.map +1 -0
- package/dist/template/supabase/proxy/adminProxy.d.ts +2 -0
- package/dist/template/supabase/proxy/adminProxy.d.ts.map +1 -0
- package/dist/template/supabase/proxy/adminProxy.js +45 -0
- package/dist/template/supabase/proxy/adminProxy.js.map +1 -0
- package/dist/template/supabase/proxy/authAdminProxy.d.ts +2 -0
- package/dist/template/supabase/proxy/authAdminProxy.d.ts.map +1 -0
- package/dist/template/supabase/proxy/authAdminProxy.js +61 -0
- package/dist/template/supabase/proxy/authAdminProxy.js.map +1 -0
- package/dist/template/supabase/proxy/authProxy.d.ts +2 -0
- package/dist/template/supabase/proxy/authProxy.d.ts.map +1 -0
- package/dist/template/supabase/proxy/authProxy.js +49 -0
- package/dist/template/supabase/proxy/authProxy.js.map +1 -0
- package/dist/template/supabase/route/googleCallback.d.ts +2 -0
- package/dist/template/supabase/route/googleCallback.d.ts.map +1 -0
- package/dist/template/supabase/route/googleCallback.js +25 -0
- package/dist/template/supabase/route/googleCallback.js.map +1 -0
- package/dist/template/supabase/schemas/user.d.ts +2 -0
- package/dist/template/supabase/schemas/user.d.ts.map +1 -0
- package/dist/template/supabase/schemas/user.js +14 -0
- package/dist/template/supabase/schemas/user.js.map +1 -0
- package/dist/template/supabase/utilBase.d.ts +1 -1
- package/dist/template/supabase/utilBase.d.ts.map +1 -1
- package/dist/template/supabase/utilBase.js +2 -2
- package/dist/types/BaseExtensionCommands.d.ts +2 -1
- package/dist/types/BaseExtensionCommands.d.ts.map +1 -1
- package/dist/types/BaseExtensionCommands.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const axiosInstanceWithLocalStorageRefreshToken = "import axios, { AxiosError, AxiosInstance, AxiosRequestConfig } from \"axios\"\nimport qs from \"qs\"\n\nimport { ENV } from \"@/configs/env\"\nimport { apiLogger } from \"@/utils/logger/api-logger\"\nimport styledConsole from \"@/utils/logger/styled-console\"\nimport { tokenStorage } from \"@/store/local/index\"\nimport { refresh } from \"./refresh\"\n\nconst isDev = ENV.NODE_ENV === \"development\"\n\nexport class HttpClient {\n private instance: AxiosInstance\n\n constructor(config?: AxiosRequestConfig) {\n this.instance = axios.create({\n baseURL: ENV.API_BASE_URL,\n timeout: 5000,\n headers: {\n \"Content-Type\": \"application/json\",\n },\n ...config,\n })\n this.setupInterceptors()\n }\n\n private setupInterceptors() {\n this.instance.interceptors.request.use(\n (config) => {\n const token = tokenStorage?.get()\n const isAccess = !!token && !!token.access\n if (isAccess) {\n config.headers.setAuthorization(`Bearer ${token.access}`);\n }\n return config\n },\n (error) => {\n return Promise.reject(error)\n },\n )\n\n this.instance.interceptors.response.use(\n (res) => {\n const { status, config: reqData, data: resData } = res\n if (isDev) apiLogger({ status, reqData, resData })\n return res\n },\n async (error: AxiosError) => {\n try {\n const { response: res, config: reqData } = error || {}\n const { status } = res || { status: 400 }\n const isUnAuthError = status === 401\n const isExpiredToken = status === 444\n\n if (isDev) apiLogger({ status, reqData, resData: error, method: \"error\" })\n\n if (isExpiredToken && reqData) {\n const refreshedConfig = await refresh(reqData)\n if (refreshedConfig) {\n return this.instance.request(refreshedConfig)\n }\n }\n\n if (isUnAuthError) {\n tokenStorage?.remove()\n }\n\n return Promise.reject(error)\n } catch (e) {\n styledConsole({\n method: \"error\",\n topic: \"UN_HANDLED\",\n title: \"axios-interceptor\",\n data: e,\n })\n return Promise.reject(e)\n }\n },\n )\n\n this.instance.defaults.paramsSerializer = (params) => {\n return qs.stringify(params, { arrayFormat: \"repeat\" })\n }\n }\n\n public getInstance(): AxiosInstance {\n return this.instance\n }\n}\n\nexport const instance = new HttpClient().getInstance()";
|
|
2
|
+
export declare const axiosInstanceWithNextServerJwt = "import axios, { AxiosError, AxiosInstance, AxiosRequestConfig } from \"axios\"\nimport qs from \"qs\"\n\nimport { ENV } from \"@/configs/env\"\nimport { apiLogger } from \"@/utils/logger/api-logger\"\nimport styledConsole from \"@/utils/logger/styled-console\"\nimport { clearTokens } from \"@/utils/jwt\"\n\nconst isDev = ENV.NODE_ENV === \"development\"\n\nlet isRefreshing = false;\nlet refreshSubscribers: ((token: string) => void)[] = [];\n\nconst onRefreshed = (token: string) => {\n refreshSubscribers.forEach((callback) => callback(token));\n refreshSubscribers = [];\n};\n\nconst addRefreshSubscriber = (callback: (token: string) => void) => {\n refreshSubscribers.push(callback);\n};\n\nexport class HttpClient {\n private instance: AxiosInstance\n\n constructor(config?: AxiosRequestConfig) {\n this.instance = axios.create({\n baseURL: ENV.API_BASE_URL,\n timeout: 5000,\n withCredentials: true, \n headers: {\n \"Content-Type\": \"application/json\",\n },\n ...config,\n })\n this.setupInterceptors()\n }\n\n private setupInterceptors() {\n this.instance.interceptors.request.use(\n (config) => config,\n (error) => Promise.reject(error),\n )\n\n this.instance.interceptors.response.use(\n (res) => {\n const { status, config: reqData, data: resData } = res\n if (isDev) apiLogger({ status, reqData, resData })\n return res\n },\n async (error: AxiosError) => {\n const { response: res, config: reqData } = error || {}\n const { status } = res || { status: 400 }\n const originalRequest = reqData as AxiosRequestConfig & { _retry?: boolean }\n const isBrowser = typeof window !== 'undefined'\n const isUnAuthError = status === 401\n const isExpiredToken = status === 444\n\n if (isExpiredToken && originalRequest && !originalRequest._retry && isBrowser) {\n originalRequest._retry = true;\n\n if (isRefreshing) {\n return new Promise((resolve) => {\n addRefreshSubscriber(() => {\n resolve(this.instance(originalRequest));\n });\n });\n }\n\n isRefreshing = true;\n\n try {\n await axios.post('/api/auth/refresh'); \n \n isRefreshing = false;\n onRefreshed('success');\n return this.instance(originalRequest);\n } catch (refreshError) {\n isRefreshing = false;\n refreshSubscribers = [];\n if (typeof window !== 'undefined') {\n window.location.href = '/login'; \n }\n return Promise.reject(refreshError);\n }\n }\n\n if (isUnAuthError) {\n await clearTokens();\n }\n\n styledConsole({\n method: \"error\",\n topic: \"UN_HANDLED\",\n title: \"axios-interceptor\",\n data: error,\n })\n return Promise.reject(error)\n },\n )\n\n this.instance.defaults.paramsSerializer = (params) => {\n return qs.stringify(params, { arrayFormat: \"repeat\" })\n }\n }\n\n public getInstance(): AxiosInstance {\n return this.instance\n }\n}\n\nexport const instance = new HttpClient().getInstance()";
|
|
3
|
+
export declare const axiosInstance = "import axios, { AxiosError, AxiosInstance, AxiosRequestConfig } from \"axios\"\nimport qs from \"qs\"\n\nimport { ENV } from \"@/configs/env\"\nimport { apiLogger } from \"@/utils/logger/api-logger\"\nimport styledConsole from \"@/utils/logger/styled-console\"\n\nconst isDev = ENV.NODE_ENV === \"development\"\n\nexport class HttpClient {\n private instance: AxiosInstance\n\n constructor(config?: AxiosRequestConfig) {\n this.instance = axios.create({\n baseURL: ENV.API_BASE_URL,\n timeout: 5000,\n headers: {\n \"Content-Type\": \"application/json\",\n },\n ...config,\n })\n this.setupInterceptors()\n }\n\n private setupInterceptors() {\n this.instance.interceptors.request.use(\n (config) => {\n return config\n },\n (error) => {\n return Promise.reject(error)\n },\n )\n\n this.instance.interceptors.response.use(\n (res) => {\n const { status, config: reqData, data: resData } = res\n if (isDev) apiLogger({ status, reqData, resData })\n return res\n },\n async (error: AxiosError) => {\n try {\n const { response: res, config: reqData } = error || {}\n const { status } = res || { status: 400 }\n\n if (isDev) apiLogger({ status, reqData, resData: error, method: \"error\" })\n\n return Promise.reject(error)\n } catch (e) {\n styledConsole({\n method: \"error\",\n topic: \"UN_HANDLED\",\n title: \"axios-interceptor\",\n data: e,\n })\n return Promise.reject(e)\n }\n },\n )\n\n this.instance.defaults.paramsSerializer = (params) => {\n return qs.stringify(params, { arrayFormat: \"repeat\" })\n }\n }\n\n public getInstance(): AxiosInstance {\n return this.instance\n }\n}\n\nexport const instance = new HttpClient().getInstance()\n";
|
|
2
4
|
//# sourceMappingURL=instance.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instance.d.ts","sourceRoot":"","sources":["../../../src/template/axios/instance.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"instance.d.ts","sourceRoot":"","sources":["../../../src/template/axios/instance.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,yCAAyC,skFA0FC,CAAA;AAEvD,eAAO,MAAM,8BAA8B,ovGA+GY,CAAA;AAEvD,eAAO,MAAM,aAAa,u4DAuEzB,CAAA"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const axiosInstanceWithLocalStorageRefreshToken = `import axios, { AxiosError, AxiosInstance, AxiosRequestConfig } from "axios"
|
|
2
2
|
import qs from "qs"
|
|
3
3
|
|
|
4
4
|
import { ENV } from "@/configs/env"
|
|
5
5
|
import { apiLogger } from "@/utils/logger/api-logger"
|
|
6
6
|
import styledConsole from "@/utils/logger/styled-console"
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
import { tokenStorage } from "@/store/local/index"
|
|
8
|
+
import { refresh } from "./refresh"
|
|
9
|
+
|
|
9
10
|
const isDev = ENV.NODE_ENV === "development"
|
|
10
11
|
|
|
11
12
|
export class HttpClient {
|
|
@@ -26,11 +27,11 @@ export class HttpClient {
|
|
|
26
27
|
private setupInterceptors() {
|
|
27
28
|
this.instance.interceptors.request.use(
|
|
28
29
|
(config) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
const token = tokenStorage?.get()
|
|
31
|
+
const isAccess = !!token && !!token.access
|
|
32
|
+
if (isAccess) {
|
|
33
|
+
config.headers.setAuthorization(\`Bearer \${token.access}\`);
|
|
34
|
+
}
|
|
34
35
|
return config
|
|
35
36
|
},
|
|
36
37
|
(error) => {
|
|
@@ -48,21 +49,21 @@ export class HttpClient {
|
|
|
48
49
|
try {
|
|
49
50
|
const { response: res, config: reqData } = error || {}
|
|
50
51
|
const { status } = res || { status: 400 }
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
const isUnAuthError = status === 401
|
|
53
|
+
const isExpiredToken = status === 444
|
|
53
54
|
|
|
54
55
|
if (isDev) apiLogger({ status, reqData, resData: error, method: "error" })
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
if (isExpiredToken && reqData) {
|
|
58
|
+
const refreshedConfig = await refresh(reqData)
|
|
59
|
+
if (refreshedConfig) {
|
|
60
|
+
return this.instance.request(refreshedConfig)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
if (isUnAuthError) {
|
|
65
|
+
tokenStorage?.remove()
|
|
66
|
+
}
|
|
66
67
|
|
|
67
68
|
return Promise.reject(error)
|
|
68
69
|
} catch (e) {
|
|
@@ -88,4 +89,188 @@ export class HttpClient {
|
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
export const instance = new HttpClient().getInstance()`;
|
|
92
|
+
export const axiosInstanceWithNextServerJwt = `import axios, { AxiosError, AxiosInstance, AxiosRequestConfig } from "axios"
|
|
93
|
+
import qs from "qs"
|
|
94
|
+
|
|
95
|
+
import { ENV } from "@/configs/env"
|
|
96
|
+
import { apiLogger } from "@/utils/logger/api-logger"
|
|
97
|
+
import styledConsole from "@/utils/logger/styled-console"
|
|
98
|
+
import { clearTokens } from "@/utils/jwt"
|
|
99
|
+
|
|
100
|
+
const isDev = ENV.NODE_ENV === "development"
|
|
101
|
+
|
|
102
|
+
let isRefreshing = false;
|
|
103
|
+
let refreshSubscribers: ((token: string) => void)[] = [];
|
|
104
|
+
|
|
105
|
+
const onRefreshed = (token: string) => {
|
|
106
|
+
refreshSubscribers.forEach((callback) => callback(token));
|
|
107
|
+
refreshSubscribers = [];
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const addRefreshSubscriber = (callback: (token: string) => void) => {
|
|
111
|
+
refreshSubscribers.push(callback);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export class HttpClient {
|
|
115
|
+
private instance: AxiosInstance
|
|
116
|
+
|
|
117
|
+
constructor(config?: AxiosRequestConfig) {
|
|
118
|
+
this.instance = axios.create({
|
|
119
|
+
baseURL: ENV.API_BASE_URL,
|
|
120
|
+
timeout: 5000,
|
|
121
|
+
withCredentials: true,
|
|
122
|
+
headers: {
|
|
123
|
+
"Content-Type": "application/json",
|
|
124
|
+
},
|
|
125
|
+
...config,
|
|
126
|
+
})
|
|
127
|
+
this.setupInterceptors()
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
private setupInterceptors() {
|
|
131
|
+
this.instance.interceptors.request.use(
|
|
132
|
+
(config) => config,
|
|
133
|
+
(error) => Promise.reject(error),
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
this.instance.interceptors.response.use(
|
|
137
|
+
(res) => {
|
|
138
|
+
const { status, config: reqData, data: resData } = res
|
|
139
|
+
if (isDev) apiLogger({ status, reqData, resData })
|
|
140
|
+
return res
|
|
141
|
+
},
|
|
142
|
+
async (error: AxiosError) => {
|
|
143
|
+
const { response: res, config: reqData } = error || {}
|
|
144
|
+
const { status } = res || { status: 400 }
|
|
145
|
+
const originalRequest = reqData as AxiosRequestConfig & { _retry?: boolean }
|
|
146
|
+
const isBrowser = typeof window !== 'undefined'
|
|
147
|
+
const isUnAuthError = status === 401
|
|
148
|
+
const isExpiredToken = status === 444
|
|
149
|
+
|
|
150
|
+
if (isExpiredToken && originalRequest && !originalRequest._retry && isBrowser) {
|
|
151
|
+
originalRequest._retry = true;
|
|
152
|
+
|
|
153
|
+
if (isRefreshing) {
|
|
154
|
+
return new Promise((resolve) => {
|
|
155
|
+
addRefreshSubscriber(() => {
|
|
156
|
+
resolve(this.instance(originalRequest));
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
isRefreshing = true;
|
|
162
|
+
|
|
163
|
+
try {
|
|
164
|
+
await axios.post('/api/auth/refresh');
|
|
165
|
+
|
|
166
|
+
isRefreshing = false;
|
|
167
|
+
onRefreshed('success');
|
|
168
|
+
return this.instance(originalRequest);
|
|
169
|
+
} catch (refreshError) {
|
|
170
|
+
isRefreshing = false;
|
|
171
|
+
refreshSubscribers = [];
|
|
172
|
+
if (typeof window !== 'undefined') {
|
|
173
|
+
window.location.href = '/login';
|
|
174
|
+
}
|
|
175
|
+
return Promise.reject(refreshError);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (isUnAuthError) {
|
|
180
|
+
await clearTokens();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
styledConsole({
|
|
184
|
+
method: "error",
|
|
185
|
+
topic: "UN_HANDLED",
|
|
186
|
+
title: "axios-interceptor",
|
|
187
|
+
data: error,
|
|
188
|
+
})
|
|
189
|
+
return Promise.reject(error)
|
|
190
|
+
},
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
this.instance.defaults.paramsSerializer = (params) => {
|
|
194
|
+
return qs.stringify(params, { arrayFormat: "repeat" })
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
public getInstance(): AxiosInstance {
|
|
199
|
+
return this.instance
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export const instance = new HttpClient().getInstance()`;
|
|
204
|
+
export const axiosInstance = `import axios, { AxiosError, AxiosInstance, AxiosRequestConfig } from "axios"
|
|
205
|
+
import qs from "qs"
|
|
206
|
+
|
|
207
|
+
import { ENV } from "@/configs/env"
|
|
208
|
+
import { apiLogger } from "@/utils/logger/api-logger"
|
|
209
|
+
import styledConsole from "@/utils/logger/styled-console"
|
|
210
|
+
|
|
211
|
+
const isDev = ENV.NODE_ENV === "development"
|
|
212
|
+
|
|
213
|
+
export class HttpClient {
|
|
214
|
+
private instance: AxiosInstance
|
|
215
|
+
|
|
216
|
+
constructor(config?: AxiosRequestConfig) {
|
|
217
|
+
this.instance = axios.create({
|
|
218
|
+
baseURL: ENV.API_BASE_URL,
|
|
219
|
+
timeout: 5000,
|
|
220
|
+
headers: {
|
|
221
|
+
"Content-Type": "application/json",
|
|
222
|
+
},
|
|
223
|
+
...config,
|
|
224
|
+
})
|
|
225
|
+
this.setupInterceptors()
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
private setupInterceptors() {
|
|
229
|
+
this.instance.interceptors.request.use(
|
|
230
|
+
(config) => {
|
|
231
|
+
return config
|
|
232
|
+
},
|
|
233
|
+
(error) => {
|
|
234
|
+
return Promise.reject(error)
|
|
235
|
+
},
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
this.instance.interceptors.response.use(
|
|
239
|
+
(res) => {
|
|
240
|
+
const { status, config: reqData, data: resData } = res
|
|
241
|
+
if (isDev) apiLogger({ status, reqData, resData })
|
|
242
|
+
return res
|
|
243
|
+
},
|
|
244
|
+
async (error: AxiosError) => {
|
|
245
|
+
try {
|
|
246
|
+
const { response: res, config: reqData } = error || {}
|
|
247
|
+
const { status } = res || { status: 400 }
|
|
248
|
+
|
|
249
|
+
if (isDev) apiLogger({ status, reqData, resData: error, method: "error" })
|
|
250
|
+
|
|
251
|
+
return Promise.reject(error)
|
|
252
|
+
} catch (e) {
|
|
253
|
+
styledConsole({
|
|
254
|
+
method: "error",
|
|
255
|
+
topic: "UN_HANDLED",
|
|
256
|
+
title: "axios-interceptor",
|
|
257
|
+
data: e,
|
|
258
|
+
})
|
|
259
|
+
return Promise.reject(e)
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
this.instance.defaults.paramsSerializer = (params) => {
|
|
265
|
+
return qs.stringify(params, { arrayFormat: "repeat" })
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
public getInstance(): AxiosInstance {
|
|
270
|
+
return this.instance
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export const instance = new HttpClient().getInstance()
|
|
275
|
+
`;
|
|
91
276
|
//# sourceMappingURL=instance.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instance.js","sourceRoot":"","sources":["../../../src/template/axios/instance.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"instance.js","sourceRoot":"","sources":["../../../src/template/axios/instance.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,yCAAyC,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uDA0FF,CAAA;AAEvD,MAAM,CAAC,MAAM,8BAA8B,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uDA+GS,CAAA;AAEvD,MAAM,CAAC,MAAM,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuE5B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nextServerJwt.d.ts","sourceRoot":"","sources":["../../../src/template/axios/nextServerJwt.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB,cAuBpC,CAAA;AAED,eAAO,MAAM,0BAA0B,cA0BtC,CAAA;AAED,eAAO,MAAM,yBAAyB,cAOrC,CAAA"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export const nextServerAuthLoginRoute = () => `import { instance } from "@/configs/axios/instance"
|
|
2
|
+
import { AUTH_ENDPOINTS, setTokens } from "@/utils/jwt"
|
|
3
|
+
import { NextResponse } from "next/server"
|
|
4
|
+
|
|
5
|
+
export async function POST(request: Request) {
|
|
6
|
+
try {
|
|
7
|
+
const body = await request.json()
|
|
8
|
+
|
|
9
|
+
const response = await instance.post(AUTH_ENDPOINTS.LOGIN, body)
|
|
10
|
+
|
|
11
|
+
const { accessToken, refreshToken, ...userData } = response.data
|
|
12
|
+
|
|
13
|
+
await setTokens(accessToken, refreshToken)
|
|
14
|
+
|
|
15
|
+
return NextResponse.json({ success: true, user: userData })
|
|
16
|
+
|
|
17
|
+
} catch (error: any) {
|
|
18
|
+
const status = error.response?.status || 500
|
|
19
|
+
const errorData = error.response?.data || { message: 'Login failed' }
|
|
20
|
+
|
|
21
|
+
return NextResponse.json(errorData, { status })
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
`;
|
|
25
|
+
export const nextServerAuthRefreshRoute = () => `import { instance } from "@/configs/axios/instance"
|
|
26
|
+
import { AUTH_ENDPOINTS, getTokens, setTokens, clearTokens } from "@/utils/jwt"
|
|
27
|
+
import { NextResponse } from "next/server"
|
|
28
|
+
|
|
29
|
+
export async function POST() {
|
|
30
|
+
const { refreshToken } = await getTokens()
|
|
31
|
+
|
|
32
|
+
if (!refreshToken) {
|
|
33
|
+
return NextResponse.json({ message: 'No refresh token' }, { status: 401 })
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
const response = await instance.post(AUTH_ENDPOINTS.REFRESH, {
|
|
38
|
+
refresh: refreshToken
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
const { accessToken, refreshToken: newRefreshToken } = response.data
|
|
42
|
+
|
|
43
|
+
await setTokens(accessToken, newRefreshToken)
|
|
44
|
+
|
|
45
|
+
return NextResponse.json({ success: true })
|
|
46
|
+
} catch {
|
|
47
|
+
await clearTokens()
|
|
48
|
+
return NextResponse.json({ message: 'Refresh failed' }, { status: 401 })
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
`;
|
|
52
|
+
export const nextServerAuthLogoutRoute = () => `import { NextResponse } from 'next/server'
|
|
53
|
+
import { clearTokens } from '@/utils/jwt'
|
|
54
|
+
|
|
55
|
+
export async function POST() {
|
|
56
|
+
await clearTokens()
|
|
57
|
+
return NextResponse.json({ success: true })
|
|
58
|
+
}
|
|
59
|
+
`;
|
|
60
|
+
//# sourceMappingURL=nextServerJwt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nextServerJwt.js","sourceRoot":"","sources":["../../../src/template/axios/nextServerJwt.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;CAuB7C,CAAA;AAED,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAG,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;CA0B/C,CAAA;AAED,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,EAAE,CAAC;;;;;;;CAO9C,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protectedProxy.d.ts","sourceRoot":"","sources":["../../../src/template/axios/protectedProxy.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,cAsC1B,CAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export const protectedProxy = () => `import { NextResponse } from 'next/server';
|
|
2
|
+
import type { NextRequest } from 'next/server';
|
|
3
|
+
import { TOKEN_KEYS } from '@/utils/jwt';
|
|
4
|
+
import { PROTECTED_ROUTES, ROUTES } from '@/generated/path/routes';
|
|
5
|
+
|
|
6
|
+
export function proxy(request: NextRequest) {
|
|
7
|
+
const { pathname } = request.nextUrl;
|
|
8
|
+
|
|
9
|
+
const isProtectedRoute = PROTECTED_ROUTES.some((route) =>
|
|
10
|
+
pathname.startsWith(route)
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
if (isProtectedRoute) {
|
|
14
|
+
const hasAccessToken = request.cookies.has(TOKEN_KEYS.ACCESS);
|
|
15
|
+
const hasRefreshToken = request.cookies.has(TOKEN_KEYS.REFRESH);
|
|
16
|
+
|
|
17
|
+
if (!hasAccessToken && !hasRefreshToken) {
|
|
18
|
+
const loginUrl = new URL(ROUTES.LOGIN, request.url);
|
|
19
|
+
loginUrl.searchParams.set('redirect', pathname);
|
|
20
|
+
return NextResponse.redirect(loginUrl);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (pathname === ROUTES.LOGIN) {
|
|
25
|
+
const hasRefreshToken = request.cookies.has(TOKEN_KEYS.REFRESH);
|
|
26
|
+
if (hasRefreshToken) {
|
|
27
|
+
return NextResponse.redirect(new URL(ROUTES.HOME, request.url));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return NextResponse.next();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const config = {
|
|
35
|
+
matcher: [
|
|
36
|
+
'/((?!api|_next/static|_next/image|favicon.ico).*)',
|
|
37
|
+
],
|
|
38
|
+
};
|
|
39
|
+
`;
|
|
40
|
+
//# sourceMappingURL=protectedProxy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protectedProxy.js","sourceRoot":"","sources":["../../../src/template/axios/protectedProxy.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsCnC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLoginHook.d.ts","sourceRoot":"","sources":["../../../src/template/axios/useLoginHook.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,cAexB,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const useLoginHook = () => `import { CommonErrorType, UserLoginRequestType, UserLoginType } from "@/generated/api/@types/data-contracts"
|
|
2
|
+
import { useMutation } from "@tanstack/react-query"
|
|
3
|
+
import axios, { AxiosError } from "axios"
|
|
4
|
+
|
|
5
|
+
export const useLoginMutation = () => {
|
|
6
|
+
// TODO: Change to the actual login type from the API
|
|
7
|
+
return useMutation<UserLoginType, AxiosError<CommonErrorType>, UserLoginRequestType>({
|
|
8
|
+
mutationKey: ["AUTH_JWT_LOGIN_CREATE"],
|
|
9
|
+
mutationFn: async (data) => {
|
|
10
|
+
const res = await axios.post("/api/auth/login", data)
|
|
11
|
+
return res.data
|
|
12
|
+
},
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
`;
|
|
16
|
+
//# sourceMappingURL=useLoginHook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLoginHook.js","sourceRoot":"","sources":["../../../src/template/axios/useLoginHook.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,YAAY,GACvB,GAAG,EAAE,CAAC;;;;;;;;;;;;;;CAcP,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLogoutHook.d.ts","sourceRoot":"","sources":["../../../src/template/axios/useLogoutHook.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,cAazB,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const useLogoutHook = () => `import { CommonErrorType } from "@/generated/api/@types/data-contracts"
|
|
2
|
+
import { useMutation } from "@tanstack/react-query"
|
|
3
|
+
import axios, { AxiosError } from "axios"
|
|
4
|
+
|
|
5
|
+
export const useLogoutMutation = () => {
|
|
6
|
+
return useMutation<void, AxiosError<CommonErrorType>, void>({
|
|
7
|
+
mutationKey: ["AUTH_JWT_LOGOUT_CREATE"],
|
|
8
|
+
mutationFn: async () => {
|
|
9
|
+
const res = await axios.post("/api/auth/logout")
|
|
10
|
+
return res.data
|
|
11
|
+
},
|
|
12
|
+
})
|
|
13
|
+
}
|
|
14
|
+
`;
|
|
15
|
+
//# sourceMappingURL=useLogoutHook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLogoutHook.js","sourceRoot":"","sources":["../../../src/template/axios/useLogoutHook.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,EAAE,CAAC;;;;;;;;;;;;;CAalC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilJwt.d.ts","sourceRoot":"","sources":["../../../src/template/axios/utilJwt.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,cAkDnB,CAAA"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export const utilJwt = () => `import { cookies } from "next/headers"
|
|
2
|
+
|
|
3
|
+
export const AUTH_ENDPOINTS = {
|
|
4
|
+
LOGIN: "/v1/user/login/", // TODO: Change to the actual login endpoint
|
|
5
|
+
REFRESH: "/v1/user/refresh/",
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const TOKEN_KEYS = {
|
|
9
|
+
ACCESS: "accessToken",
|
|
10
|
+
REFRESH: "refreshToken",
|
|
11
|
+
} as const
|
|
12
|
+
|
|
13
|
+
const cookieOptions = {
|
|
14
|
+
httpOnly: true,
|
|
15
|
+
secure: process.env.NODE_ENV === "production",
|
|
16
|
+
sameSite: process.env.NODE_ENV === "production" ? "lax" : "none",
|
|
17
|
+
path: "/",
|
|
18
|
+
} as const
|
|
19
|
+
|
|
20
|
+
export async function setTokens(accessToken: string, refreshToken?: string) {
|
|
21
|
+
const cookieStore = await cookies()
|
|
22
|
+
|
|
23
|
+
cookieStore.set(TOKEN_KEYS.ACCESS, accessToken, {
|
|
24
|
+
...cookieOptions,
|
|
25
|
+
maxAge: 60 * 15, // 15min
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
if (refreshToken) {
|
|
29
|
+
cookieStore.set(TOKEN_KEYS.REFRESH, refreshToken, {
|
|
30
|
+
...cookieOptions,
|
|
31
|
+
maxAge: 60 * 60 * 24 * 7, // 7days
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function clearTokens() {
|
|
37
|
+
const cookieStore = await cookies()
|
|
38
|
+
|
|
39
|
+
cookieStore.delete(TOKEN_KEYS.ACCESS)
|
|
40
|
+
cookieStore.delete(TOKEN_KEYS.REFRESH)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function getTokens() {
|
|
44
|
+
const cookieStore = await cookies()
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
accessToken: cookieStore.get(TOKEN_KEYS.ACCESS)?.value,
|
|
48
|
+
refreshToken: cookieStore.get(TOKEN_KEYS.REFRESH)?.value,
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
`;
|
|
52
|
+
//# sourceMappingURL=utilJwt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilJwt.js","sourceRoot":"","sources":["../../../src/template/axios/utilJwt.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkD5B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../../src/template/supabase/actions/auth.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,GAAI,YAAY,OAAO,WA6DtD,CAAA"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export const supabaseAuthActions = (isNeedAuth) => `"use server"
|
|
2
|
+
|
|
3
|
+
${!isNeedAuth ? `import { ROUTES } from "@/generated/path/routes"` : 'import { ENV } from "@/configs/env"'}
|
|
4
|
+
import { createClient } from "@/lib/supabase/server"
|
|
5
|
+
import { redirect } from "next/navigation"
|
|
6
|
+
|
|
7
|
+
export async function login(formData: FormData) {
|
|
8
|
+
const supabase = await createClient()
|
|
9
|
+
const email = formData.get("email") as string
|
|
10
|
+
const password = formData.get("password") as string
|
|
11
|
+
|
|
12
|
+
const { error } = await supabase.auth.signInWithPassword({
|
|
13
|
+
email,
|
|
14
|
+
password,
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
if (error) {
|
|
18
|
+
redirect(${isNeedAuth ? '"/login?message=login_failed"' : '"/"'})
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
redirect(${isNeedAuth ? '"/"' : "ROUTES.ADMIN"})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
${isNeedAuth
|
|
25
|
+
? `export async function signup(formData: FormData) {
|
|
26
|
+
const supabase = await createClient()
|
|
27
|
+
const email = formData.get("email") as string
|
|
28
|
+
const password = formData.get("password") as string
|
|
29
|
+
|
|
30
|
+
const { error } = await supabase.auth.signUp({
|
|
31
|
+
email,
|
|
32
|
+
password,
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
if (error) {
|
|
36
|
+
redirect("/login?message=signup_failed")
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
redirect("/login?message=signup_success")
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function signInWithGoogle() {
|
|
43
|
+
const supabase = await createClient()
|
|
44
|
+
const { data, error } = await supabase.auth.signInWithOAuth({
|
|
45
|
+
provider: "google",
|
|
46
|
+
options: {
|
|
47
|
+
redirectTo: \`\${ENV.DOMAIN}/api/auth/google/callback\`,
|
|
48
|
+
},
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
if (error) {
|
|
52
|
+
redirect("/login?message=signin_with_failed&provider=google")
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (data.url) {
|
|
56
|
+
redirect(data.url)
|
|
57
|
+
}
|
|
58
|
+
}`
|
|
59
|
+
: ""}
|
|
60
|
+
`;
|
|
61
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../../src/template/supabase/actions/auth.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,UAAmB,EAAE,EAAE,CAAC;;EAE1D,CAAC,UAAU,CAAC,CAAC,CAAC,kDAAkD,CAAC,CAAC,CAAC,qCAAqC;;;;;;;;;;;;;;;eAe3F,UAAU,CAAC,CAAC,CAAC,+BAA+B,CAAC,CAAC,CAAC,KAAK;;;aAGtD,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,cAAc;;;EAI9C,UAAU;IACR,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiCJ;IACE,CAAC,CAAC,EACN;CACC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crud.d.ts","sourceRoot":"","sources":["../../../../src/template/supabase/actions/crud.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,mBAAmB,GAAI,WAAW,MAAM,WAsCpD,CAAA;AAED,eAAO,MAAM,mBAAmB,GAAI,WAAW,MAAM,WA8BpD,CAAA"}
|