update
This commit is contained in:
@ -1,11 +1,10 @@
|
||||
import { User as Auth0UserModel } from '@auth0/auth0-spa-js';
|
||||
|
||||
import { getData, setData } from '@/utils';
|
||||
import { type AuthModel } from './_models';
|
||||
// import https from 'https'
|
||||
|
||||
const AUTH_LOCAL_STORAGE_KEY = `${import.meta.env.VITE_APP_NAME}-auth-v${
|
||||
import.meta.env.VITE_APP_VERSION
|
||||
}`;
|
||||
const AUTH_LOCAL_STORAGE_KEY = `${import.meta.env.VITE_APP_NAME}-auth-v${import.meta.env.VITE_APP_VERSION
|
||||
}`;
|
||||
|
||||
const getAuth = (): AuthModel | undefined => {
|
||||
try {
|
||||
@ -40,25 +39,12 @@ const removeAuth = () => {
|
||||
export function setupAxios(axios: any) {
|
||||
axios.defaults.headers.Accept = 'application/json';
|
||||
axios.interceptors.request.use(
|
||||
(config: { headers: { Authorization: string }; params?: any; url?: any }) => {
|
||||
(config: { headers: { Authorization: string }; params?: any; url?: any; httpsAgent: any }) => {
|
||||
const auth = getAuth();
|
||||
|
||||
if (auth?.access_token) {
|
||||
config.headers.Authorization = `Bearer ${auth.access_token}`;
|
||||
|
||||
if (
|
||||
config.url &&
|
||||
!config.url.includes('api/b/') &&
|
||||
!config.url.includes('api/bg/') &&
|
||||
!config.url.includes('api/c/')
|
||||
) {
|
||||
config.params = {
|
||||
...config.params,
|
||||
token: auth.access_token || ''
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return config;
|
||||
},
|
||||
async (err: any) => await Promise.reject(err)
|
||||
|
||||
@ -22,7 +22,6 @@ const loginSchema = Yup.object().shape({
|
||||
const initialValues = {
|
||||
username: '',
|
||||
password: '',
|
||||
application: 'credit',
|
||||
remember: false
|
||||
};
|
||||
|
||||
@ -46,8 +45,8 @@ const Login = () => {
|
||||
throw new Error('JWTProvider is required for this form.');
|
||||
}
|
||||
|
||||
await login(values.username, values.password, values.application);
|
||||
console.log(login);
|
||||
await login(values.username, values.password);
|
||||
// console.log(login);
|
||||
|
||||
if (values.remember) {
|
||||
localStorage.setItem('username', values.username);
|
||||
@ -75,28 +74,14 @@ const Login = () => {
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="card max-w-[390px] border-0 shadow-none w-full">
|
||||
<form className="card-body flex flex-col gap-5 p-5" onSubmit={formik.handleSubmit} noValidate>
|
||||
<div className="flex align-center justify-center text-center mb-2.5">
|
||||
<img
|
||||
src={toAbsoluteUrl('/media/app/bri_tl_logo.png')}
|
||||
className="h-[50px] max-w-none mb-2 text-center"
|
||||
alt=""
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-col gap-3">
|
||||
<div className="flex gap-3 items-center">
|
||||
<div>
|
||||
<img
|
||||
src={toAbsoluteUrl('/media/app/brilian_apps_logo.png')}
|
||||
className="h-[40px] max-w-none"
|
||||
alt=""
|
||||
/>
|
||||
</div>
|
||||
<h3 className="font-semibold text-gray-700" style={{ fontSize: '18px' }}>
|
||||
/ Pengajuan Kredit
|
||||
</h3>
|
||||
</div>
|
||||
<div className="card max-w-[390px] w-full">
|
||||
<form
|
||||
className="card-body flex flex-col gap-5 p-10"
|
||||
onSubmit={formik.handleSubmit}
|
||||
noValidate
|
||||
>
|
||||
<div className="text-center">
|
||||
<h3 className="text-lg font-semibold text-gray-900 leading-none ">Sign in</h3>
|
||||
</div>
|
||||
{formik.status && <Alert variant="danger">{formik.status}</Alert>}
|
||||
<div className="flex flex-col gap-1">
|
||||
@ -176,9 +161,8 @@ const Login = () => {
|
||||
{loading ? 'Please wait...' : 'Sign In'}
|
||||
</button>
|
||||
<div>
|
||||
<p className="text-2sm" style={{ fontSize: '12px', letterSpacing: 0.25 }}>
|
||||
Copyright {moment().year()} © Bank Rakyat Indonesia Timor Leste.
All rights
|
||||
reserved.
|
||||
<p className="text-2sm text-center" style={{ fontSize: '12px', letterSpacing: 0.25 }}>
|
||||
Copyright {moment().year()} © Telkomcel All rights reserved.
|
||||
</p>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@ -14,7 +14,7 @@ import { type AuthModel, type UserModel } from '@/auth';
|
||||
import { apiConfig } from '@/config/api.config';
|
||||
import { doSaveLogActivity } from '@/actions/GlobalActions';
|
||||
|
||||
const API_URL = apiConfig.service_user;
|
||||
const API_URL = apiConfig.service_dashboard;
|
||||
|
||||
export const LOGIN_URL = `${API_URL}/login`;
|
||||
export const FORGOT_PASSWORD_URL = `${API_URL}/reset_password`;
|
||||
@ -28,7 +28,7 @@ interface AuthContextProps {
|
||||
saveAuth: (auth: AuthModel | undefined) => void;
|
||||
currentUser: UserModel | undefined;
|
||||
setCurrentUser: Dispatch<SetStateAction<UserModel | undefined>>;
|
||||
login: (email: string, password: string, application: string) => Promise<void>;
|
||||
login: (email: string, password: string) => Promise<void>;
|
||||
requestPasswordResetLink: (email: string) => Promise<void>;
|
||||
changePassword: (token: string, password: string, password_confirmation: string) => Promise<void>;
|
||||
getUser: () => Promise<AxiosResponse<any> | {}>;
|
||||
@ -70,13 +70,12 @@ const AuthProvider = ({ children }: PropsWithChildren) => {
|
||||
}
|
||||
};
|
||||
|
||||
const login = async (username: string, password: string, application: string) => {
|
||||
const login = async (username: string, password: string) => {
|
||||
try {
|
||||
const { data: auth } = await axios
|
||||
.post(LOGIN_URL, { username, password, application })
|
||||
.post(LOGIN_URL, { username, password })
|
||||
.then((response) => response.data);
|
||||
|
||||
// console.log('auth :', auth);
|
||||
saveAuth({ ...auth.token, id: auth.user.id, role_name: auth.role_name, user: auth.user });
|
||||
setCurrentUser(auth.user);
|
||||
const createActivity = {
|
||||
|
||||
Reference in New Issue
Block a user