feat: add auth via google

This commit is contained in:
Sonny
2024-04-27 18:14:40 +02:00
committed by Sonny
parent 2531242615
commit df4185bd62
18 changed files with 450 additions and 46 deletions

View File

@@ -1,7 +1,9 @@
import '../css/app.css';
import { hydrateRoot } from 'react-dom/client';
import { createInertiaApp } from '@inertiajs/react';
/// <reference path="../../adonisrc.ts" />
import { resolvePageComponent } from '@adonisjs/inertia/helpers';
import { createInertiaApp } from '@inertiajs/react';
import { hydrateRoot } from 'react-dom/client';
import '../css/app.css';
const appName = import.meta.env.VITE_APP_NAME || 'AdonisJS';

View File

@@ -0,0 +1,5 @@
import { usePage } from '@inertiajs/react';
import type { InertiaPage } from '~/types/inertia';
const useUser = () => usePage<InertiaPage>().props.auth;
export default useUser;

View File

@@ -1,17 +1,28 @@
import { InferPageProps } from '@adonisjs/inertia/types';
import { Head } from '@inertiajs/react';
import useUser from '~/hooks/use_user';
import type AppsController from '../../app/controllers/apps_controller';
export default function Home(_: InferPageProps<AppsController, 'index'>) {
const { isAuthenticated, user } = useUser();
export default function Home(props: { version: number }) {
return (
<>
<Head title="Homepage" />
<div className="container">
<div className="title">AdonisJS {props.version} x Inertia x React</div>
<div className="title">AdonisJS x Inertia x React</div>
<span>
Learn more about AdonisJS and Inertia.js by visiting the{' '}
<a href="https://docs.adonisjs.com/guides/inertia">AdonisJS documentation</a>.
</span>
<span>{isAuthenticated ? 'Authenticated' : 'Not authenticated'}</span>
<span>
{isAuthenticated ? <a href="/auth/logout">Logout</a> : <a href="/auth/login">Login</a>}
</span>
<pre>{JSON.stringify(user, null, 2)}</pre>
</div>
</>
);

4
inertia/types/app.d.ts vendored Normal file
View File

@@ -0,0 +1,4 @@
import { Serialize } from '@tuyau/utils/types';
import type UserModel from '../../app/models/user';
type User = Serialize<UserModel>;

8
inertia/types/inertia.d.ts vendored Normal file
View File

@@ -0,0 +1,8 @@
import type { User } from './app';
export type InertiaPage<T extends Record<string, unknown> = Record<string, unknown>> = T & {
auth: {
user?: User;
isAuthenticated: boolean;
};
};