add env var to remove user registration
This commit is contained in:
@@ -112,4 +112,6 @@ return [
|
|||||||
|
|
||||||
'password_timeout' => 10800,
|
'password_timeout' => 10800,
|
||||||
|
|
||||||
|
'register' => (bool) env('REGISTER_DISABLED', false),
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import React from "react"
|
|||||||
import {Link, NavLink, useLocation} from "react-router-dom"
|
import {Link, NavLink, useLocation} from "react-router-dom"
|
||||||
import useAuthUser from "../hooks/AuthUser"
|
import useAuthUser from "../hooks/AuthUser"
|
||||||
import Tracker from "./TimeTrackers/Tracker"
|
import Tracker from "./TimeTrackers/Tracker"
|
||||||
|
import {env} from "../utilities/env"
|
||||||
|
|
||||||
const Header = () => {
|
const Header = () => {
|
||||||
|
|
||||||
@@ -15,7 +16,6 @@ const Header = () => {
|
|||||||
<div>
|
<div>
|
||||||
<Link to="/">Ticcat</Link>
|
<Link to="/">Ticcat</Link>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{authUser && <Tracker />}
|
{authUser && <Tracker />}
|
||||||
{authUser
|
{authUser
|
||||||
? <span className="flex gap-2">
|
? <span className="flex gap-2">
|
||||||
@@ -23,7 +23,7 @@ const Header = () => {
|
|||||||
</span>
|
</span>
|
||||||
: <span className="flex gap-2">
|
: <span className="flex gap-2">
|
||||||
<Link to="/connexion">Connexion</Link>
|
<Link to="/connexion">Connexion</Link>
|
||||||
{/*<Link to="/sinscrire">S'inscrire</Link>*/}
|
{env.VITE_REGISTER_DISABLED === 'false' && <Link to="/sinscrire">S'inscrire</Link>}
|
||||||
</span>}
|
</span>}
|
||||||
</div>
|
</div>
|
||||||
<nav className="flex gap-5 bg-gray-600 px-5">
|
<nav className="flex gap-5 bg-gray-600 px-5">
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export const AuthUserProvider = ({children}: PropsWithChildren) => {
|
|||||||
// @ts-expect-error 401 error to redirect
|
// @ts-expect-error 401 error to redirect
|
||||||
if (error.response.status === 401) {
|
if (error.response.status === 401) {
|
||||||
console.info('no user login')
|
console.info('no user login')
|
||||||
if (!['/connexion', '/inscription'].includes(window.location.pathname)) {
|
if (!['/connexion', '/sinscrire'].includes(window.location.pathname)) {
|
||||||
window.location.href = '/connexion'
|
window.location.href = '/connexion'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ import useAuthUser from "../hooks/AuthUser"
|
|||||||
import Register from "./Auth/Register"
|
import Register from "./Auth/Register"
|
||||||
import ToDoShow from "./ToDos/ToDoShow"
|
import ToDoShow from "./ToDos/ToDoShow"
|
||||||
import TimeTrackersIndex from "./TimeTrackersIndex"
|
import TimeTrackersIndex from "./TimeTrackersIndex"
|
||||||
|
import {env} from "../utilities/env"
|
||||||
|
|
||||||
const Router = () => {
|
const Router = () => {
|
||||||
|
|
||||||
console.log('router')
|
|
||||||
const {loadingAuthUser} = useAuthUser()
|
const {loadingAuthUser} = useAuthUser()
|
||||||
|
|
||||||
return <>
|
return <>
|
||||||
@@ -24,7 +24,7 @@ const Router = () => {
|
|||||||
<Route path="/" element={<Home />} />
|
<Route path="/" element={<Home />} />
|
||||||
<Route path="/profile" element={<Profile />} />
|
<Route path="/profile" element={<Profile />} />
|
||||||
<Route path="/connexion" element={<Login />} />
|
<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="/todos/:id" element={<ToDoShow />} />
|
||||||
<Route path="/times" element={<TimeTrackersIndex />} />
|
<Route path="/times" element={<TimeTrackersIndex />} />
|
||||||
</Routes>
|
</Routes>
|
||||||
|
|||||||
14
resources/js/utilities/env.ts
Normal file
14
resources/js/utilities/env.ts
Normal 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,
|
||||||
|
}
|
||||||
@@ -18,9 +18,12 @@ use Illuminate\Support\Facades\Route;
|
|||||||
|
|
||||||
Route::post('/login', [AuthController::class, 'login'])->name('login');
|
Route::post('/login', [AuthController::class, 'login'])->name('login');
|
||||||
Route::post('/forgot', [AuthController::class, 'forgot'])->name('forgot');
|
Route::post('/forgot', [AuthController::class, 'forgot'])->name('forgot');
|
||||||
Route::post('/register', [AuthController::class, 'register'])->name('register');
|
|
||||||
Route::post('/reset', [AuthController::class, 'reset'])->name('reset');
|
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::middleware('auth:sanctum')->group(function () {
|
||||||
Route::get('/user', [AuthController::class, 'user'])->name('user');
|
Route::get('/user', [AuthController::class, 'user'])->name('user');
|
||||||
Route::delete('/logout', [AuthController::class, 'logout'])->name('logout');
|
Route::delete('/logout', [AuthController::class, 'logout'])->name('logout');
|
||||||
|
|||||||
Reference in New Issue
Block a user