mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-09 15:05:35 +00:00
feat: add i18n with type safety
This commit is contained in:
@@ -5,15 +5,15 @@ const PATHS = {
|
||||
GOOGLE: '/auth/google',
|
||||
},
|
||||
HOME: '/',
|
||||
APP: '/app',
|
||||
DASHBOARD: '/dashboard',
|
||||
SHARED: '/shared',
|
||||
PRIVACY: '/privacy',
|
||||
TERMS: '/terms',
|
||||
ADMIN: '/admin',
|
||||
CATEGORY: {
|
||||
CREATE: '/category/create',
|
||||
EDIT: '/category/edit',
|
||||
REMOVE: '/category/remove',
|
||||
COLLECTION: {
|
||||
CREATE: '/collections/create',
|
||||
EDIT: '/collections/edit',
|
||||
REMOVE: '/collections/remove',
|
||||
},
|
||||
LINK: {
|
||||
CREATE: '/link/create',
|
||||
@@ -21,14 +21,15 @@ const PATHS = {
|
||||
REMOVE: '/link/remove',
|
||||
},
|
||||
API: {
|
||||
CATEGORY: '/api/category',
|
||||
COLLECTION: '/collections',
|
||||
LINK: '/api/link',
|
||||
},
|
||||
NOT_FOUND: '/404',
|
||||
SERVER_ERROR: '/505',
|
||||
AUTHOR: 'https://www.sonny.dev/',
|
||||
REPO_GITHUB: 'https://github.com/Sonny93/my-links',
|
||||
EXTENSION: 'https://chromewebstore.google.com/detail/mylinks/agkmlplihacolkakgeccnbhphnepphma',
|
||||
EXTENSION:
|
||||
'https://chromewebstore.google.com/detail/mylinks/agkmlplihacolkakgeccnbhphnepphma',
|
||||
} as const;
|
||||
|
||||
export default PATHS;
|
||||
|
||||
@@ -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}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user