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 = {
|
export const authProvider: AuthProvider = {
|
||||||
login: async ({email, password}) => {
|
login: async ({email, password}) => {
|
||||||
try {
|
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`, {
|
const response = await axios.post(`${API_URL}/auth/login`, {
|
||||||
email,
|
email,
|
||||||
password,
|
password,
|
||||||
@ -63,6 +87,8 @@ export const authProvider: AuthProvider = {
|
|||||||
},
|
},
|
||||||
check: async () => {
|
check: async () => {
|
||||||
const token = localStorage.getItem(TOKEN_KEY)
|
const token = localStorage.getItem(TOKEN_KEY)
|
||||||
|
const user = localStorage.getItem('user')
|
||||||
|
|
||||||
if (!token) {
|
if (!token) {
|
||||||
return {
|
return {
|
||||||
authenticated: false,
|
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 {
|
try {
|
||||||
const response = await axios.get(`${API_URL}/auth/me`, {
|
const response = await axios.get(`${API_URL}/auth/me`, {
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import {DataGrid, type DataGridProps, type GridColumnVisibilityModel} from '@mui/x-data-grid'
|
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 {ExportButton} from '@refinedev/mui'
|
||||||
import {useExport} from '@refinedev/core'
|
import {useExport} from '@refinedev/core'
|
||||||
import React, {useState, useEffect, useMemo} from 'react'
|
import React, {useState, useEffect, useMemo} from 'react'
|
||||||
@ -113,7 +113,9 @@ export const CustomDataGrid = ({hasCoordinates = false, columns = [], resource,
|
|||||||
)}
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
<ExportButton onClick={triggerExport} loading={exportLoading} />
|
<ExportButton onClick={triggerExport} loading={exportLoading} hideText={false}>
|
||||||
|
<Typography sx={{marginLeft: '-2px'}}>Экспорт</Typography>
|
||||||
|
</ExportButton>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Stack>
|
</Stack>
|
||||||
)
|
)
|
||||||
|
@ -8,8 +8,8 @@ export const Login = () => {
|
|||||||
title={<ThemedTitleV2 collapsed={false} text="Белые Ночи" icon={<ProjectIcon style={{color: '#7f6b58'}} />} />}
|
title={<ThemedTitleV2 collapsed={false} text="Белые Ночи" icon={<ProjectIcon style={{color: '#7f6b58'}} />} />}
|
||||||
formProps={{
|
formProps={{
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
email: 'demo@refine.dev',
|
email: 'test@wn.ru',
|
||||||
password: 'demodemo',
|
password: 'testwn',
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
Loading…
Reference in New Issue
Block a user