@innertia-solutions/innertia-nuxt 0.1.16 → 0.1.18
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/composables/useAuth.js +6 -3
- package/composables/useTheme.ts +26 -0
- package/package.json +1 -1
package/composables/useAuth.js
CHANGED
|
@@ -14,7 +14,8 @@ export function useAuth() {
|
|
|
14
14
|
*/
|
|
15
15
|
async function performLogin(context, email, password, remember = false) {
|
|
16
16
|
authStore.rememberUser = remember
|
|
17
|
-
|
|
17
|
+
// Endpoint agnóstico de contexto: el contexto viaja en el payload (y luego en el JWT).
|
|
18
|
+
const data = await api.post('auth/login', { email, password, context })
|
|
18
19
|
authStore.saveToken(data.token ?? data.access_token)
|
|
19
20
|
authStore.setCurrentContext(context)
|
|
20
21
|
queryClient.clear()
|
|
@@ -75,7 +76,9 @@ export function useAuth() {
|
|
|
75
76
|
* Returns the URL string from the backend.
|
|
76
77
|
*/
|
|
77
78
|
async function getOauthRedirectUrl(context, provider) {
|
|
78
|
-
|
|
79
|
+
// Endpoint agnóstico: el contexto viaja como query param (el backend lo
|
|
80
|
+
// codifica en el state de OAuth y lo recupera en el callback).
|
|
81
|
+
const data = await api.get(`auth/${provider}/redirect`, { params: { context } })
|
|
79
82
|
return data.url
|
|
80
83
|
}
|
|
81
84
|
|
|
@@ -83,7 +86,7 @@ export function useAuth() {
|
|
|
83
86
|
* Handle OAuth callback. Same success path as performLogin.
|
|
84
87
|
*/
|
|
85
88
|
async function handleOauthCallback(context, provider, code) {
|
|
86
|
-
const data = await api.post(
|
|
89
|
+
const data = await api.post(`auth/${provider}/callback`, { code, context })
|
|
87
90
|
authStore.saveToken(data.token ?? data.access_token)
|
|
88
91
|
authStore.setCurrentContext(context)
|
|
89
92
|
queryClient.clear()
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useTheme — lee y cambia el tema dark/light.
|
|
3
|
+
*
|
|
4
|
+
* Usa la cookie `hs_theme` para compatibilidad SSR con el plugin appearance.ts
|
|
5
|
+
* y con el componente <AppSwitchColorTheme />.
|
|
6
|
+
*/
|
|
7
|
+
export function useTheme() {
|
|
8
|
+
const cookie = useCookie<'dark' | 'light'>('hs_theme', {
|
|
9
|
+
default: () => 'light',
|
|
10
|
+
sameSite: 'lax',
|
|
11
|
+
maxAge: 60 * 60 * 24 * 365,
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
const isDark = computed(() => cookie.value === 'dark')
|
|
15
|
+
|
|
16
|
+
const toggle = () => {
|
|
17
|
+
const next = cookie.value === 'dark' ? 'light' : 'dark'
|
|
18
|
+
cookie.value = next
|
|
19
|
+
if (import.meta.client) {
|
|
20
|
+
document.documentElement.classList.toggle('dark', next === 'dark')
|
|
21
|
+
localStorage.setItem('hs_theme', next)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return { isDark, toggle }
|
|
26
|
+
}
|