-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: github login * style: code format * feat: callback and login step enhancements * fix: login ssr disable
- Loading branch information
1 parent
3fe6115
commit ef64d39
Showing
8 changed files
with
3,512 additions
and
4,319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.base { | ||
display: grid; | ||
align-items: center; | ||
justify-content: center; | ||
width: 100%; | ||
height: 100vh; | ||
.wrap { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 12px; | ||
.text { | ||
font-weight: bold; | ||
font-size: large; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
"use client"; | ||
import { getGithubLoginStatus } from "@/lib/apis/global"; | ||
import { getUserInfo } from "@/lib/apis/user"; | ||
import { useAppDispatch } from "@/redux"; | ||
import { addAccount } from "@/redux/features/userList"; | ||
import { useRouter } from "next/navigation"; | ||
import { useEffect } from "react"; | ||
import styles from "./page.module.scss"; | ||
import { Player } from "@lottiefiles/react-lottie-player"; | ||
import BackLayout from "@/components/Layout/BackLayout"; | ||
|
||
const GithubCallback = ({ | ||
searchParams, | ||
}: { | ||
searchParams: { | ||
code: string; | ||
state: string; | ||
}; | ||
}) => { | ||
const { code, state } = searchParams; | ||
const router = useRouter(); | ||
const dispatch = useAppDispatch(); | ||
|
||
console.log("code", code, "state", state); | ||
|
||
useEffect(() => { | ||
getGithubLoginStatus(code, state).then((githubRes) => { | ||
if (githubRes.data.Success) { | ||
localStorage.setItem( | ||
"Token", | ||
JSON.stringify(githubRes.data.Data.loginToken), | ||
); | ||
getUserInfo().then((res) => { | ||
if (res.data.Success) { | ||
const data = res.data.Data; | ||
dispatch( | ||
addAccount({ | ||
nickName: "ming", | ||
email: data.email, | ||
Token: githubRes.data.Data.loginToken, | ||
userId: data.userId, | ||
}), | ||
); | ||
|
||
router.replace("/home"); | ||
} | ||
}); | ||
} else { | ||
if (githubRes.data.ErrCode === 50000) { | ||
return <div>Github 登录失败</div>; | ||
} | ||
router.replace(`/login?oauthTicket=${githubRes.data.Data.oauthTicket}`); | ||
} | ||
}); | ||
}, [code, dispatch, router, state]); | ||
|
||
return ( | ||
<div className={styles["base"]}> | ||
<BackLayout type="green" /> | ||
<div className={styles["wrap"]}> | ||
{/* <Icon iconNode={cupSaucer} size={48} strokeWidth={1.25} /> */} | ||
<Player | ||
autoplay={true} | ||
loop={false} | ||
src="/svg/done.json" | ||
style={{ height: "64px", width: "64px" }} | ||
keepLastFrame | ||
renderer="svg" | ||
/> | ||
<div className={styles["text"]}>授权成功,正在重定向</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default GithubCallback; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.