diff --git a/.env b/.env index 41e7780..0fd4e04 100644 --- a/.env +++ b/.env @@ -11,4 +11,7 @@ NEXT_PUBLIC_DEV_CODE_SERVER_HOST='http://192.168.5.119:8443' #NEXT_PUBLIC_DEV_SERVER_HOST='http://192.168.5.129:80' # 开发环境-119 -NEXT_PUBLIC_DEV_SERVER_HOST='http://192.168.5.119:80' \ No newline at end of file +#NEXT_PUBLIC_DEV_SERVER_HOST='http://192.168.5.119:80' + +# 后端本地环境 +NEXT_PUBLIC_DEV_SERVER_HOST='http://192.168.5.158:8103' \ No newline at end of file diff --git a/src/api/sso.ts b/src/api/sso.ts index dbd283b..93bce4b 100644 --- a/src/api/sso.ts +++ b/src/api/sso.ts @@ -33,7 +33,7 @@ export const ssoLogin = ({ username, password }: Record) => { }); }; -export const verify = ({ username, password }): Promise => { +export const verifyOld = ({ username, password }): Promise => { return fetch('/api/user-center/verify', { method: 'POST', headers: { @@ -48,4 +48,34 @@ export const verify = ({ username, password }): Promise => { } return data; }); +}; + +export const verify = ({ username, password }): Promise => { + return fetch('/api/sso/verify', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ username, password: password }) + }).then(async (res) => { + const data = await res.json(); + return data; + }); +}; + + +export const ssoCallBack = ({ ticket, redirectUrl }) => { + const params = new URLSearchParams({ ticket, redirectUrl }); + return fetch(`/api/sso/callback?${params.toString()}`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json' + } + }).then(async (res) => { + const data = await res.json(); + if (data && res.status === 200) { + localStorage.setItem('userStatus', 'login'); + } + return data; + }); }; \ No newline at end of file diff --git a/src/pages/login/form.tsx b/src/pages/login/form.tsx index abfde07..9864599 100644 --- a/src/pages/login/form.tsx +++ b/src/pages/login/form.tsx @@ -9,12 +9,13 @@ import { import { FormInstance } from '@arco-design/web-react/es/Form'; import { IconLock, IconUser } from '@arco-design/web-react/icon'; import React, { useEffect, useRef, useState } from 'react'; -import { ssoLogin, verify } from '@/api/sso'; +import { ssoCallBack, ssoLogin, verify, verifyOld } from '@/api/sso'; import useStorage from '@/utils/useStorage'; import useLocale from '@/utils/useLocale'; import locale from './locale'; import styles from './style/index.module.less'; import { encryptLoginParams, decryptLoginParams } from '@/utils/crypto'; +import { setToken } from '@/utils/auth'; export default function LoginForm() { const formRef = useRef(); @@ -37,8 +38,10 @@ export default function LoginForm() { } // 记录登录状态 localStorage.setItem('userStatus', 'login'); + // 保存Token + setToken(token as string); // 跳转首页 - // window.location.href = '/dashboard/workplace'; + window.location.href = '/dashboard/workplace'; } async function loginRequest(params) { @@ -47,8 +50,13 @@ export default function LoginForm() { try { const res = await verify(params as any); if (res.code === 200) { - await ssoLogin(params); - afterLoginSuccess(params); + if (res.data.code === 200) { + const tokenData = await ssoCallBack(res.data); + afterLoginSuccess(params, tokenData.data); + } + else { + setErrorMessage(res.msg); + } } else { setErrorMessage(res.msg);