add mock
user into authProvider
This commit is contained in:
parent
fb0deab271
commit
da3a162adb
@ -13,9 +13,33 @@ class AuthError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
const MOCK_USER = {
|
||||
email: 'test@wn.ru',
|
||||
password: 'testwn',
|
||||
name: 'Константин Иванов',
|
||||
avatar: 'https://i.pravatar.cc/300',
|
||||
// roles: ['admin'],
|
||||
}
|
||||
|
||||
export const authProvider: AuthProvider = {
|
||||
login: async ({email, password}) => {
|
||||
try {
|
||||
if (email === MOCK_USER.email && password === MOCK_USER.password) {
|
||||
const mockResponse = {
|
||||
token: 'mock-jwt-token',
|
||||
user: MOCK_USER,
|
||||
}
|
||||
|
||||
localStorage.setItem(TOKEN_KEY, mockResponse.token)
|
||||
localStorage.setItem('user', JSON.stringify(mockResponse.user))
|
||||
|
||||
return {
|
||||
success: true,
|
||||
redirectTo: '/',
|
||||
}
|
||||
}
|
||||
|
||||
// If not mock user, try real API
|
||||
const response = await axios.post(`${API_URL}/auth/login`, {
|
||||
email,
|
||||
password,
|
||||
@ -63,6 +87,8 @@ export const authProvider: AuthProvider = {
|
||||
},
|
||||
check: async () => {
|
||||
const token = localStorage.getItem(TOKEN_KEY)
|
||||
const user = localStorage.getItem('user')
|
||||
|
||||
if (!token) {
|
||||
return {
|
||||
authenticated: false,
|
||||
@ -70,6 +96,14 @@ export const authProvider: AuthProvider = {
|
||||
}
|
||||
}
|
||||
|
||||
// If using mock token, skip API verification
|
||||
if (token === 'mock-jwt-token' && user) {
|
||||
return {
|
||||
authenticated: true,
|
||||
}
|
||||
}
|
||||
|
||||
// For real tokens, verify with API
|
||||
try {
|
||||
const response = await axios.get(`${API_URL}/auth/me`, {
|
||||
headers: {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import {DataGrid, type DataGridProps, type GridColumnVisibilityModel} from '@mui/x-data-grid'
|
||||
import {Stack, Button} from '@mui/material'
|
||||
import {Stack, Button, Typography} from '@mui/material'
|
||||
import {ExportButton} from '@refinedev/mui'
|
||||
import {useExport} from '@refinedev/core'
|
||||
import React, {useState, useEffect, useMemo} from 'react'
|
||||
@ -113,7 +113,9 @@ export const CustomDataGrid = ({hasCoordinates = false, columns = [], resource,
|
||||
)}
|
||||
</Stack>
|
||||
|
||||
<ExportButton onClick={triggerExport} loading={exportLoading} />
|
||||
<ExportButton onClick={triggerExport} loading={exportLoading} hideText={false}>
|
||||
<Typography sx={{marginLeft: '-2px'}}>Экспорт</Typography>
|
||||
</ExportButton>
|
||||
</Stack>
|
||||
</Stack>
|
||||
)
|
||||
|
@ -8,8 +8,8 @@ export const Login = () => {
|
||||
title={<ThemedTitleV2 collapsed={false} text="Белые Ночи" icon={<ProjectIcon style={{color: '#7f6b58'}} />} />}
|
||||
formProps={{
|
||||
defaultValues: {
|
||||
email: 'demo@refine.dev',
|
||||
password: 'demodemo',
|
||||
email: 'test@wn.ru',
|
||||
password: 'testwn',
|
||||
},
|
||||
}}
|
||||
/>
|
||||
|
Loading…
Reference in New Issue
Block a user