add env var to remove user registration

This commit is contained in:
Romulus21
2024-03-04 17:17:46 +01:00
parent 6dd147c3e2
commit 6609738650
6 changed files with 25 additions and 6 deletions

View File

@@ -112,4 +112,6 @@ return [
'password_timeout' => 10800,
'register' => (bool) env('REGISTER_DISABLED', false),
];

View File

@@ -2,6 +2,7 @@ import React from "react"
import {Link, NavLink, useLocation} from "react-router-dom"
import useAuthUser from "../hooks/AuthUser"
import Tracker from "./TimeTrackers/Tracker"
import {env} from "../utilities/env"
const Header = () => {
@@ -15,7 +16,6 @@ const Header = () => {
<div>
<Link to="/">Ticcat</Link>
</div>
{authUser && <Tracker />}
{authUser
? <span className="flex gap-2">
@@ -23,7 +23,7 @@ const Header = () => {
</span>
: <span className="flex gap-2">
<Link to="/connexion">Connexion</Link>
{/*<Link to="/sinscrire">S'inscrire</Link>*/}
{env.VITE_REGISTER_DISABLED === 'false' && <Link to="/sinscrire">S&apos;inscrire</Link>}
</span>}
</div>
<nav className="flex gap-5 bg-gray-600 px-5">

View File

@@ -31,7 +31,7 @@ export const AuthUserProvider = ({children}: PropsWithChildren) => {
// @ts-expect-error 401 error to redirect
if (error.response.status === 401) {
console.info('no user login')
if (!['/connexion', '/inscription'].includes(window.location.pathname)) {
if (!['/connexion', '/sinscrire'].includes(window.location.pathname)) {
window.location.href = '/connexion'
}
}

View File

@@ -9,10 +9,10 @@ import useAuthUser from "../hooks/AuthUser"
import Register from "./Auth/Register"
import ToDoShow from "./ToDos/ToDoShow"
import TimeTrackersIndex from "./TimeTrackersIndex"
import {env} from "../utilities/env"
const Router = () => {
console.log('router')
const {loadingAuthUser} = useAuthUser()
return <>
@@ -24,7 +24,7 @@ const Router = () => {
<Route path="/" element={<Home />} />
<Route path="/profile" element={<Profile />} />
<Route path="/connexion" element={<Login />} />
<Route path="/inscription" element={<Register />} />
{env.VITE_REGISTER_DISABLED === 'false' && <Route path="/sinscrire" element={<Register />} />}
<Route path="/todos/:id" element={<ToDoShow />} />
<Route path="/times" element={<TimeTrackersIndex />} />
</Routes>

View File

@@ -0,0 +1,14 @@
// @ts-expect-error use import var
export const env: envProps = import.meta.env
interface envProps {
BASE_URL: string,
DEV: boolean,
MODE: string,
PROD: boolean,
VITE_APP_NAME: string,
VITE_REGISTER_DISABLED: string,
}

View File

@@ -18,9 +18,12 @@ use Illuminate\Support\Facades\Route;
Route::post('/login', [AuthController::class, 'login'])->name('login');
Route::post('/forgot', [AuthController::class, 'forgot'])->name('forgot');
Route::post('/register', [AuthController::class, 'register'])->name('register');
Route::post('/reset', [AuthController::class, 'reset'])->name('reset');
if (! config('auth.register')) {
Route::post('/register', [AuthController::class, 'register'])->name('register');
}
Route::middleware('auth:sanctum')->group(function () {
Route::get('/user', [AuthController::class, 'user'])->name('user');
Route::delete('/logout', [AuthController::class, 'logout'])->name('logout');