feat: add i18n with type safety

This commit is contained in:
Sonny
2024-04-30 00:36:13 +02:00
committed by Sonny
parent 31f22d382e
commit 2cc490b611
32 changed files with 706 additions and 30 deletions

View File

@@ -4,8 +4,17 @@ import { collectionValidator } from '#validators/collection';
import type { HttpContext } from '@adonisjs/core/http';
export default class CollectionsController {
async index({ inertia }: HttpContext) {
return inertia.render('app');
async index({ auth, inertia }: HttpContext) {
const collections = await Collection.findManyBy('author_id', auth.user!.id);
const collectionsWithLinks = await Promise.all(
collections.map((collection) => {
collection.load('links');
return collection;
})
);
return inertia.render('dashboard', { collections: collectionsWithLinks });
}
async showCreatePage({ inertia }: HttpContext) {
@@ -25,6 +34,6 @@ export default class CollectionsController {
response: HttpContext['response'],
collectionId: Collection['id']
) {
return response.redirect(`${PATHS.APP}?categoryId=${collectionId}`);
return response.redirect(`${PATHS.DASHBOARD}?categoryId=${collectionId}`);
}
}

View File

@@ -30,7 +30,14 @@ export default class UsersController {
return response.redirect(this.redirectTo);
}
const { email, id: providerId, name, nickName, avatarUrl, token } = await google.user();
const {
email,
id: providerId,
name,
nickName,
avatarUrl,
token,
} = await google.user();
const user = await User.updateOrCreate(
{
email,
@@ -49,7 +56,7 @@ export default class UsersController {
session.flash('flash', 'Successfully authenticated');
logger.info(`[${user.email}] auth success`);
response.redirect(this.redirectTo);
response.redirect(PATHS.DASHBOARD);
}
async logout({ auth, response, session }: HttpContext) {