Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c17f95351f |
@@ -2,7 +2,7 @@ PUBLIC_URL=http://localhost:3000/
|
|||||||
PORT=3000
|
PORT=3000
|
||||||
PRIMARY_APP_API_URL=https://preview.keenthemes.com/metronic8/laravel/api
|
PRIMARY_APP_API_URL=https://preview.keenthemes.com/metronic8/laravel/api
|
||||||
REACT_APP_BASE_LAYOUT_CONFIG_KEY='metronic-react-demo1-8150'
|
REACT_APP_BASE_LAYOUT_CONFIG_KEY='metronic-react-demo1-8150'
|
||||||
REACT_APP_API_URL=https://preview.keenthemes.com/metronic8/laravel/api
|
REACT_APP_API_URL=https://float-gat.dev.chiefsoft.net/en/userweb/api/v1
|
||||||
REACT_APP_VERSION=v8.1.5
|
REACT_APP_VERSION=v8.1.5
|
||||||
REACT_APP_THEME_NAME=WrenchBoard
|
REACT_APP_THEME_NAME=WrenchBoard
|
||||||
REACT_APP_THEME_DEMO=dashboard
|
REACT_APP_THEME_DEMO=dashboard
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import {getUserByToken, login} from '../core/_requests'
|
|||||||
import {toAbsoluteUrl} from '../../../../_metronic/helpers'
|
import {toAbsoluteUrl} from '../../../../_metronic/helpers'
|
||||||
import {useAuth} from '../core/Auth'
|
import {useAuth} from '../core/Auth'
|
||||||
|
|
||||||
|
import {useNavigate} from 'react-router-dom'
|
||||||
|
|
||||||
const loginSchema = Yup.object().shape({
|
const loginSchema = Yup.object().shape({
|
||||||
email: Yup.string()
|
email: Yup.string()
|
||||||
.email('Wrong email format')
|
.email('Wrong email format')
|
||||||
@@ -32,6 +34,7 @@ const initialValues = {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export function Login() {
|
export function Login() {
|
||||||
|
const navigate = useNavigate()
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const {saveAuth, setCurrentUser} = useAuth()
|
const {saveAuth, setCurrentUser} = useAuth()
|
||||||
|
|
||||||
@@ -42,9 +45,13 @@ export function Login() {
|
|||||||
setLoading(true)
|
setLoading(true)
|
||||||
try {
|
try {
|
||||||
const {data: auth} = await login(values.email, values.password)
|
const {data: auth} = await login(values.email, values.password)
|
||||||
|
console.log('yes')
|
||||||
saveAuth(auth)
|
saveAuth(auth)
|
||||||
const {data: user} = await getUserByToken(auth.api_token)
|
// const {data: user} = await getUserByToken(auth.session_token)
|
||||||
setCurrentUser(user)
|
console.log('yes2')
|
||||||
|
// setCurrentUser(user)
|
||||||
|
setCurrentUser(auth.profile)
|
||||||
|
navigate('/dashboard')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
saveAuth(undefined)
|
saveAuth(undefined)
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ const AuthInit: FC<WithChildren> = ({children}) => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
if (!didRequest.current) {
|
if (!didRequest.current) {
|
||||||
logout()
|
// logout()
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
setShowSplashScreen(false)
|
setShowSplashScreen(false)
|
||||||
@@ -86,8 +86,8 @@ const AuthInit: FC<WithChildren> = ({children}) => {
|
|||||||
return () => (didRequest.current = true)
|
return () => (didRequest.current = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auth && auth.api_token) {
|
if (auth && auth.session_token) {
|
||||||
requestUser(auth.api_token)
|
requestUser(auth.session_token)
|
||||||
} else {
|
} else {
|
||||||
logout()
|
logout()
|
||||||
setShowSplashScreen(false)
|
setShowSplashScreen(false)
|
||||||
|
|||||||
@@ -52,8 +52,8 @@ export function setupAxios(axios: any) {
|
|||||||
axios.interceptors.request.use(
|
axios.interceptors.request.use(
|
||||||
(config: {headers: {Authorization: string}}) => {
|
(config: {headers: {Authorization: string}}) => {
|
||||||
const auth = getAuth()
|
const auth = getAuth()
|
||||||
if (auth && auth.api_token) {
|
if (auth && auth.session_token) {
|
||||||
config.headers.Authorization = `Bearer ${auth.api_token}`
|
config.headers.Authorization = `Bearer ${auth.session_token}`
|
||||||
}
|
}
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
export interface AuthModel {
|
export interface AuthModel {
|
||||||
api_token: string
|
session_token: string
|
||||||
refreshToken?: string
|
refreshToken?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ export const REQUEST_PASSWORD_URL = `${API_URL}/forgot_password`
|
|||||||
// Server should return AuthModel
|
// Server should return AuthModel
|
||||||
export function login(email: string, password: string) {
|
export function login(email: string, password: string) {
|
||||||
return axios.post<AuthModel>(LOGIN_URL, {
|
return axios.post<AuthModel>(LOGIN_URL, {
|
||||||
email,
|
username: email,
|
||||||
password,
|
password: password,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ export function requestPassword(email: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getUserByToken(token: string) {
|
export function getUserByToken(token: string) {
|
||||||
return axios.post<UserModel>(GET_USER_BY_ACCESSTOKEN_URL, {
|
return axios.get<UserModel>(GET_USER_BY_ACCESSTOKEN_URL, {
|
||||||
api_token: token,
|
session_token: token,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user