@@ -10,6 +10,7 @@ import Image from 'next/image'
1010import { DiscordUserInfo , getDiscordUserInfo } from '../../helpers/discordAuth'
1111import { getSession } from 'next-auth/react'
1212import { Session } from '../../@types/auth'
13+ import { CURRICULUM_PATH , LOGIN_PATH } from '../../constants'
1314
1415type ConnectToDiscordSuccessProps = {
1516 errorCode : number
@@ -21,8 +22,7 @@ type ConnectToDiscordSuccessProps = {
2122type DiscordErrorPageProps = {
2223 error : Error
2324 username : string
24- navPath : string
25- navText : string
25+ errorCode ?: ErrorCode
2626}
2727
2828type Error = {
@@ -41,12 +41,22 @@ const DISCORD_BUGS_FEEDBACK_URL =
4141const DiscordErrorPage : React . FC < DiscordErrorPageProps > = ( {
4242 username,
4343 error,
44- navPath,
45- navText
44+ errorCode
4645} ) => {
47- let errorMessage = < > </ > ,
48- errorLog = < > </ >
49- if ( ! username ) {
46+ const isDiscordError = errorCode === ErrorCode . DISCORD_ERROR
47+ const isUserNotLoggedIn = errorCode === ErrorCode . USER_NOT_LOGGED_IN
48+ const isDiscordAccountUsed =
49+ errorCode === ErrorCode . DIFFERENT_ACCOUNT_IS_CONNECTED
50+
51+ let errorMessage = < > </ >
52+ let errorLog = < > </ >
53+ let navText = isDiscordError ? 'Try Again' : 'Curriculum'
54+ let navPath = CURRICULUM_PATH
55+
56+ if ( isUserNotLoggedIn ) {
57+ navText = 'Log In Here'
58+ navPath = LOGIN_PATH
59+
5060 errorMessage = (
5161 < >
5262 < p > You need to be logged in to connect to Discord.</ p >
@@ -66,6 +76,7 @@ const DiscordErrorPage: React.FC<DiscordErrorPageProps> = ({
6676 </ >
6777 )
6878 }
79+
6980 if ( error ?. message ) {
7081 errorLog = (
7182 < >
@@ -75,10 +86,33 @@ const DiscordErrorPage: React.FC<DiscordErrorPageProps> = ({
7586 </ >
7687 )
7788 }
89+
90+ if ( isDiscordAccountUsed ) {
91+ errorMessage = (
92+ < >
93+ < p >
94+ Sorry, but it looks like the Discord account you are trying to link to
95+ your C0D3 account is already in use by another account.
96+ </ p >
97+ < p >
98+ To fix this, you can either use a different Discord account or, if the
99+ account you are trying to link is already connected to a different
100+ C0D3 account, you can go to that account and unlink the Discord
101+ account. Then, come back to this account and try linking the Discord
102+ account again.
103+ </ p >
104+ </ >
105+ )
106+ }
107+
78108 return (
79109 < >
80110 < Title title = "Error" />
81- < Card title = "Error" >
111+ < Card
112+ title = {
113+ isDiscordAccountUsed ? 'Discord account is already used' : 'Error'
114+ }
115+ >
82116 < div className = "mt-3" > { errorMessage } </ div >
83117 < p >
84118 If this problem persists, please ask for help in our{ ' ' }
@@ -102,36 +136,16 @@ const DiscordErrorPage: React.FC<DiscordErrorPageProps> = ({
102136
103137export const ConnectToDiscordSuccess : React . FC < ConnectToDiscordSuccessProps > &
104138 WithLayout = ( { errorCode, username, userInfo, error } ) => {
105- if ( errorCode === ErrorCode . DIFFERENT_ACCOUNT_IS_CONNECTED ) {
139+ if ( errorCode ) {
106140 return (
107141 < DiscordErrorPage
108142 username = { username }
109143 error = { error }
110- navPath = "/curriculum"
111- navText = "Curriculum"
144+ errorCode = { errorCode }
112145 />
113146 )
114147 }
115148
116- if ( errorCode === ErrorCode . DISCORD_ERROR )
117- return (
118- < DiscordErrorPage
119- username = { username }
120- error = { error }
121- navPath = "/curriculum"
122- navText = "Try Again"
123- />
124- )
125- if ( errorCode === ErrorCode . USER_NOT_LOGGED_IN )
126- return (
127- < DiscordErrorPage
128- username = ""
129- error = { error }
130- navPath = "/login"
131- navText = "Log In Here"
132- />
133- )
134-
135149 return (
136150 < >
137151 < Title title = "Success!" />
@@ -189,6 +203,7 @@ export const getServerSideProps = async ({
189203 id : sessionUser . id
190204 }
191205 } )
206+
192207 if ( ! user ) return { props : { errorCode : ErrorCode . USER_NOT_LOGGED_IN } }
193208
194209 const userInfo = await getDiscordUserInfo ( user )
0 commit comments