-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
168 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export default defineNuxtRouteMiddleware(async (middleware) => { | ||
const nuxtApp = useNuxtApp(); | ||
const localeRoute = useLocaleRoute(); | ||
const { loggedIn } = useUserSession(); | ||
|
||
// Si el usuario está logueado, lo redirige a su biblioteca | ||
if (loggedIn.value) { | ||
const libraryRoute = localeRoute('library', nuxtApp.$i18n.locale.value); | ||
const libraryPath = libraryRoute != null ? libraryRoute.path : '/'; | ||
|
||
return navigateTo(libraryPath); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export default defineNuxtRouteMiddleware(async (middleware) => { | ||
const nuxtApp = useNuxtApp(); | ||
const localeRoute = useLocaleRoute(); | ||
const { loggedIn } = useUserSession(); | ||
|
||
// Si el usuario no está logueado, lo redirige al login | ||
if (!loggedIn.value) { | ||
const loginRoute = localeRoute('login', nuxtApp.$i18n.locale.value); | ||
const loginPath = loginRoute != null ? loginRoute.path : '/'; | ||
|
||
return navigateTo(loginPath); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { SessionResponse } from "~/types/auth"; | ||
|
||
export default defineEventHandler(async (event) => { | ||
const config = useRuntimeConfig(); | ||
const body = await readBody(event); | ||
|
||
const response = await $fetch<SessionResponse>(config.public.backendUrl + '/auth/register', { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
email: body.email, | ||
password: body.password, | ||
}), | ||
}); | ||
|
||
await replaceUserSession(event, { | ||
user: { | ||
email: response.user.email, | ||
avatar: response.user.avatar, | ||
isAdmin: response.user.isAdmin, | ||
isVerified: response.user.isVerified, | ||
}, | ||
access_token: response.access_token, | ||
refresh_token: response.refresh_token, | ||
}, { | ||
maxAge: Number(config.nuxtSessionTime), | ||
}); | ||
|
||
return { | ||
success: true, | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters