处理登录验证
This commit is contained in:
parent
5296880dbb
commit
577cc7d042
|
@ -3,6 +3,18 @@
|
|||
@tailwind utilities;
|
||||
body{
|
||||
color:#fff;
|
||||
padding-bottom: constant(safe-area-inset-bottom);
|
||||
padding-bottom: env(safe-area-inset-bottom);
|
||||
}
|
||||
footer{
|
||||
/* Fallback for non-iOS devices */
|
||||
bottom: 0;
|
||||
|
||||
/* iOS 11.0+ */
|
||||
bottom: constant(safe-area-inset-bottom);
|
||||
|
||||
/* iOS 11.2+ */
|
||||
bottom: env(safe-area-inset-bottom);
|
||||
}
|
||||
/* :root {
|
||||
--foreground-rgb: 0, 0, 0;
|
||||
|
|
144
app/layout.js
144
app/layout.js
|
@ -46,7 +46,10 @@ export default function RootLayout({ children }) {
|
|||
type="image/x-icon"
|
||||
></link>
|
||||
<link rel="icon" href="/favicon.png" type="image/png"></link>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
|
||||
{/* <meta
|
||||
name="viewport"
|
||||
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
|
||||
/> */}
|
||||
<meta
|
||||
name="description"
|
||||
content={metadata.description}
|
||||
|
@ -62,9 +65,9 @@ export default function RootLayout({ children }) {
|
|||
{/* <!-- 全屏设置 --> */}
|
||||
<meta
|
||||
name="viewport"
|
||||
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui"
|
||||
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui,viewport-fit=cover"
|
||||
/>
|
||||
|
||||
<meta name="apple-touch-fullscreen" content="yes" />
|
||||
{/* <!-- 网站开启对 web app 程序的支持 具体表现为去除浏览器地址栏和底部导航栏 :先保存为桌面书签,然后通过书签打开即可生效--> */}
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
{/* <!-- 用来定义顶部状态栏的形式默认是default为白色 black为黑色 black-translucent为灰色半透明(会占据屏幕的约20px,不同的设备可能会有差异)--> */}
|
||||
|
@ -73,34 +76,125 @@ export default function RootLayout({ children }) {
|
|||
name="apple-mobile-web-app-status-bar-style"
|
||||
content="black-translucent"
|
||||
/>
|
||||
{/* <!-- apple-touch-startup-image用来配置启动动画 --> */}
|
||||
{/* <!-- 这里要注意,这里图片的尺寸要和设备的静态图片显示尺寸完全对应,差一个像素都会导致启动动画无法显示 --> */}
|
||||
{/* <!-- 下面列举了iPhone的所有尺寸(ps:为了方便大家就全部贴出来了!!) --> */}
|
||||
{/* <!-- iPhone 678 startup image @2x--> */}
|
||||
<link href={process.env.NEXT_PUBLIC_WEB_ASSETS_URL+"/images/launchPage/750_1334.png"} media="(device-width: 375px) and (device-height: 667px) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image"/>
|
||||
{/* <!-- iPhone 678p startup image @3x--> */}
|
||||
<link href={process.env.NEXT_PUBLIC_WEB_ASSETS_URL+"/images/launchPage/1242_2208.png"} media="(device-width: 414px) and (device-height: 736px) and (-webkit-device-pixel-ratio: 3)" rel="apple-touch-startup-image"/>
|
||||
{/* <!-- iPhone X Xs startup image @3x--> */}
|
||||
<link href={process.env.NEXT_PUBLIC_WEB_ASSETS_URL+"/images/launchPage/1125_2436.png"} media="(device-width: 375px) and (device-height: 812px) and (-webkit-device-pixel-ratio: 3)" rel="apple-touch-startup-image"/>
|
||||
{/* <!-- iPhone XR startup image @2X --> */}
|
||||
<link href={process.env.NEXT_PUBLIC_WEB_ASSETS_URL+"/images/launchPage/828_1792.png"} media="(device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image"/>
|
||||
{/* <!-- iPhone XR Max startup image @3x--> */}
|
||||
<link href={process.env.NEXT_PUBLIC_WEB_ASSETS_URL+"/images/launchPage/640_960.png"} media="(device-width: 320px) and (device-height: 480px) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image"/>
|
||||
<link href={process.env.NEXT_PUBLIC_WEB_ASSETS_URL+"/images/launchPage/640_1136.png"} media="(device-width: 320px) and (device-height: 568) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image"/>
|
||||
<link href={process.env.NEXT_PUBLIC_WEB_ASSETS_URL+"/images/launchPage/1080_1920.png"} media="(device-width: 360px) and (device-height: 640px) and (-webkit-device-pixel-ratio: 3)" rel="apple-touch-startup-image"/>
|
||||
<link href={process.env.NEXT_PUBLIC_WEB_ASSETS_URL+"/images/launchPage/1080_2340.png"} media="(device-width: 360px) and (device-height: 780px) and (-webkit-device-pixel-ratio: 3)" rel="apple-touch-startup-image"/>
|
||||
<link href={process.env.NEXT_PUBLIC_WEB_ASSETS_URL+"/images/launchPage/1170_2532.png"} media="(device-width: 390px) and (device-height: 844px) and (-webkit-device-pixel-ratio: 3)" rel="apple-touch-startup-image"/>
|
||||
<link href={process.env.NEXT_PUBLIC_WEB_ASSETS_URL+"/images/launchPage/1179_2556.png"} media="(device-width: 393px) and (device-height: 852px) and (-webkit-device-pixel-ratio: 3)" rel="apple-touch-startup-image"/>
|
||||
<link href={process.env.NEXT_PUBLIC_WEB_ASSETS_URL+"/images/launchPage/1242_2688.png"} media="(device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 3)" rel="apple-touch-startup-image"/>
|
||||
<link href={process.env.NEXT_PUBLIC_WEB_ASSETS_URL+"/images/launchPage/1284_2778.png"} media="(device-width: 428px) and (device-height: 926px) and (-webkit-device-pixel-ratio: 3)" rel="apple-touch-startup-image"/>
|
||||
<link href={process.env.NEXT_PUBLIC_WEB_ASSETS_URL+"/images/launchPage/1290_2796.png"} media="(device-width: 430px) and (device-height: 932px) and (-webkit-device-pixel-ratio: 3)" rel="apple-touch-startup-image"/>
|
||||
{/* <!-- apple-touch-startup-image用来配置启动动画 --> */}
|
||||
{/* <!-- 这里要注意,这里图片的尺寸要和设备的静态图片显示尺寸完全对应,差一个像素都会导致启动动画无法显示 --> */}
|
||||
{/* <!-- 下面列举了iPhone的所有尺寸(ps:为了方便大家就全部贴出来了!!) --> */}
|
||||
{/* <!-- iPhone 678 startup image @2x--> */}
|
||||
<link
|
||||
href={
|
||||
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
|
||||
"/images/launchPage/750_1334.png"
|
||||
}
|
||||
media="(device-width: 375px) and (device-height: 667px) and (-webkit-device-pixel-ratio: 2)"
|
||||
rel="apple-touch-startup-image"
|
||||
/>
|
||||
{/* <!-- iPhone 678p startup image @3x--> */}
|
||||
<link
|
||||
href={
|
||||
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
|
||||
"/images/launchPage/1242_2208.png"
|
||||
}
|
||||
media="(device-width: 414px) and (device-height: 736px) and (-webkit-device-pixel-ratio: 3)"
|
||||
rel="apple-touch-startup-image"
|
||||
/>
|
||||
{/* <!-- iPhone X Xs startup image @3x--> */}
|
||||
<link
|
||||
href={
|
||||
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
|
||||
"/images/launchPage/1125_2436.png"
|
||||
}
|
||||
media="(device-width: 375px) and (device-height: 812px) and (-webkit-device-pixel-ratio: 3)"
|
||||
rel="apple-touch-startup-image"
|
||||
/>
|
||||
{/* <!-- iPhone XR startup image @2X --> */}
|
||||
<link
|
||||
href={
|
||||
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
|
||||
"/images/launchPage/828_1792.png"
|
||||
}
|
||||
media="(device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 2)"
|
||||
rel="apple-touch-startup-image"
|
||||
/>
|
||||
{/* <!-- iPhone XR Max startup image @3x--> */}
|
||||
<link
|
||||
href={
|
||||
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
|
||||
"/images/launchPage/640_960.png"
|
||||
}
|
||||
media="(device-width: 320px) and (device-height: 480px) and (-webkit-device-pixel-ratio: 2)"
|
||||
rel="apple-touch-startup-image"
|
||||
/>
|
||||
<link
|
||||
href={
|
||||
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
|
||||
"/images/launchPage/640_1136.png"
|
||||
}
|
||||
media="(device-width: 320px) and (device-height: 568) and (-webkit-device-pixel-ratio: 2)"
|
||||
rel="apple-touch-startup-image"
|
||||
/>
|
||||
<link
|
||||
href={
|
||||
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
|
||||
"/images/launchPage/1080_1920.png"
|
||||
}
|
||||
media="(device-width: 360px) and (device-height: 640px) and (-webkit-device-pixel-ratio: 3)"
|
||||
rel="apple-touch-startup-image"
|
||||
/>
|
||||
<link
|
||||
href={
|
||||
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
|
||||
"/images/launchPage/1080_2340.png"
|
||||
}
|
||||
media="(device-width: 360px) and (device-height: 780px) and (-webkit-device-pixel-ratio: 3)"
|
||||
rel="apple-touch-startup-image"
|
||||
/>
|
||||
<link
|
||||
href={
|
||||
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
|
||||
"/images/launchPage/1170_2532.png"
|
||||
}
|
||||
media="(device-width: 390px) and (device-height: 844px) and (-webkit-device-pixel-ratio: 3)"
|
||||
rel="apple-touch-startup-image"
|
||||
/>
|
||||
<link
|
||||
href={
|
||||
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
|
||||
"/images/launchPage/1179_2556.png"
|
||||
}
|
||||
media="(device-width: 393px) and (device-height: 852px) and (-webkit-device-pixel-ratio: 3)"
|
||||
rel="apple-touch-startup-image"
|
||||
/>
|
||||
<link
|
||||
href={
|
||||
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
|
||||
"/images/launchPage/1242_2688.png"
|
||||
}
|
||||
media="(device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 3)"
|
||||
rel="apple-touch-startup-image"
|
||||
/>
|
||||
<link
|
||||
href={
|
||||
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
|
||||
"/images/launchPage/1284_2778.png"
|
||||
}
|
||||
media="(device-width: 428px) and (device-height: 926px) and (-webkit-device-pixel-ratio: 3)"
|
||||
rel="apple-touch-startup-image"
|
||||
/>
|
||||
<link
|
||||
href={
|
||||
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
|
||||
"/images/launchPage/1290_2796.png"
|
||||
}
|
||||
media="(device-width: 430px) and (device-height: 932px) and (-webkit-device-pixel-ratio: 3)"
|
||||
rel="apple-touch-startup-image"
|
||||
/>
|
||||
</head>
|
||||
<body className={`${inter.className} h-full`}>
|
||||
<main className={`w-full bg-deepBg h-full`}>
|
||||
{withAuth(<Provider store={store}>{children}</Provider>)}
|
||||
{/* <Provider store={store}>{children}</Provider> */}
|
||||
</main>
|
||||
<footer className="fixed bottom-0 left-0 w-screen bg-black">
|
||||
<footer className="fixed left-0 w-screen bg-black">
|
||||
<div>
|
||||
<BottomNav />
|
||||
</div>
|
||||
|
|
|
@ -15,7 +15,7 @@ import { useRouter } from "next/navigation";
|
|||
import styles from "./index.module.scss";
|
||||
import { JSEncrypt } from "jsencrypt";
|
||||
import { handleLogin } from "@/store/actions";
|
||||
import { saveUserInfo, removeUserInfo } from "@/utils/storeInfo";
|
||||
import { saveUserInfo, get } from "@/utils/storeInfo";
|
||||
import { connect } from "react-redux";
|
||||
import { cryptoPassword } from "@/utils/crypto";
|
||||
import requireAPI from "@/utils/requireAPI";
|
||||
|
@ -56,12 +56,11 @@ function Login({ handleLogin }) {
|
|||
}
|
||||
handleLogin({ isSignin: false, userToken: null });
|
||||
checkAuth().then(res=>{
|
||||
if(res){
|
||||
router.push("/")
|
||||
}else{
|
||||
removeUserInfo();
|
||||
// signOut();
|
||||
const account = get("account")
|
||||
if(res && account){
|
||||
router.replace("/")
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import React, { useEffect, useState, useMemo,useCallback } from "react";
|
|||
import Photos from "../Photos";
|
||||
import { useRouter } from "next/navigation";
|
||||
import PaySpacePost from "../PaySpacePost";
|
||||
import { Image, Popover, Divider } from "antd-mobile";
|
||||
import { Image, Popover, Divider, Toast } from "antd-mobile";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { faAngleRight } from "@fortawesome/free-solid-svg-icons";
|
||||
import { handleFollow, thumbsUp } from "@/api/public";
|
||||
|
@ -27,7 +27,7 @@ export default function PostItem({
|
|||
const [isCreator, setIsCreator] = useState(false);
|
||||
useEffect(() => {
|
||||
const account = get("account");
|
||||
if (account.mid === data.mid) setIsCreator(true);
|
||||
if (account?.mid === data.mid) setIsCreator(true);
|
||||
return () => {
|
||||
router.prefetch("/profile/" + data.mid);
|
||||
};
|
||||
|
|
|
@ -3,46 +3,45 @@ import { useRouter, usePathname, useSearchParams } from "next/navigation";
|
|||
import { useEffect } from "react";
|
||||
import { get } from "@/utils/storeInfo";
|
||||
import { Toast } from "antd-mobile";
|
||||
import {save} from "@/utils/storeInfo"
|
||||
import { save } from "@/utils/storeInfo";
|
||||
import { removeUserInfo } from "@/utils/storeInfo";
|
||||
export default function WithAuth(WrappedComponent) {
|
||||
const router = useRouter();
|
||||
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
useEffect(() => {
|
||||
if(searchParams.get("inviter")){
|
||||
save("inviter",Number(searchParams.get("inviter")))
|
||||
if (searchParams.get("inviter")) {
|
||||
save("inviter", Number(searchParams.get("inviter")));
|
||||
}
|
||||
if(!pathname.includes("webView") && !pathname.includes("login") ){
|
||||
if (!pathname.includes("webView") && !pathname.includes("login")) {
|
||||
checkLogin();
|
||||
}
|
||||
|
||||
|
||||
// console.log("isLogin",!pathname.includes("webView") && !pathname.includes("login"))
|
||||
}, [pathname]);
|
||||
const checkLogin = async () => {
|
||||
const hasToken = await get("token");
|
||||
// console.log("hasToken", hasToken);
|
||||
if (hasToken) {
|
||||
const hasToken = get("token");
|
||||
// console.log("hasToken", hasToken);
|
||||
if (hasToken) {
|
||||
const currentIsLogin = await checkAuth();
|
||||
if (!currentIsLogin) {
|
||||
Toast.show({
|
||||
icon: "fail",
|
||||
content: "当前登录失效,请重新登录",
|
||||
position: "top",
|
||||
});
|
||||
router.push("/login");
|
||||
}else{
|
||||
if(pathname.includes("login")){
|
||||
router.replace("/")
|
||||
}
|
||||
const currentIsLogin = await checkAuth();
|
||||
if (!currentIsLogin) {
|
||||
Toast.show({
|
||||
icon: "fail",
|
||||
content: "当前登录失效,请重新登录",
|
||||
position: "top",
|
||||
});
|
||||
removeUserInfo();
|
||||
router.push("/login");
|
||||
} else {
|
||||
if (pathname.includes("login")) {
|
||||
router.push("/");
|
||||
}
|
||||
}
|
||||
} else if(!searchParams.get("forgetPassword")) {
|
||||
} else if (!searchParams.get("forgetPassword")) {
|
||||
removeUserInfo();
|
||||
router.push("/login");
|
||||
}
|
||||
};
|
||||
return WrappedComponent;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,11 @@ import { get } from "./storeInfo";
|
|||
export async function checkAuth() {
|
||||
try {
|
||||
const data = await requireAPI("POST", `/api/login/validate`);
|
||||
return data.ret === 1;
|
||||
if(data.ret === 1){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
import baseRequest from "./baseRequest";
|
||||
import { get } from "./storeInfo";
|
||||
|
||||
// import { useRouter } from "next/navigation";
|
||||
// import webviewBaseRequest from "@/utils/webviewBaseRequest";
|
||||
|
||||
// 创建一个封装 fetch 的函数
|
||||
export default function customFetch(method, url, options = {}, mid) {
|
||||
export default function customFetch(method, url, options = {}, needMid) {
|
||||
const base = baseRequest();
|
||||
// 默认选项
|
||||
const defaultOptions = {
|
||||
|
@ -19,8 +18,9 @@ export default function customFetch(method, url, options = {}, mid) {
|
|||
// 可以添加其他默认选项
|
||||
};
|
||||
let newBody = { ...options?.body };
|
||||
if (mid) {
|
||||
let mid = get("account").mid;
|
||||
if (needMid) {
|
||||
let mid = get("account")?.mid;
|
||||
if(!mid) return;
|
||||
newBody.mid = mid;
|
||||
}
|
||||
const body = JSON.stringify({ ...base, ...newBody });
|
||||
|
|
Loading…
Reference in New Issue