@@ -8,21 +8,21 @@ import {
88 Strip ,
99} from "@canonical/react-components" ;
1010import { useDispatch , useSelector } from "react-redux" ;
11- import { useLocation , useNavigate } from "react-router" ;
11+ import { Link , useLocation , useNavigate } from "react-router" ;
1212
1313import { useCreateSession , useGetCallback } from "@/app/api/query/auth" ;
1414import PageContent from "@/app/base/components/PageContent" ;
15+ import urls from "@/app/base/urls" ;
1516import { statusActions } from "@/app/store/status" ;
1617import statusSelectors from "@/app/store/status/selectors" ;
1718
1819export const Labels = {
1920 MissingParams : "Missing code or state in the callback URL." ,
20- CallbackError :
21- "An error occurred during authentication. Please try logging in again." ,
21+ CallbackError : "An error occurred during authentication." ,
2222 AlreadyAuthenticated : "You are already authenticated. Redirecting..." ,
2323} ;
2424
25- export const LoginCallback = ( ) : React . ReactElement => {
25+ const LoginCallback = ( ) : React . ReactElement => {
2626 const location = useLocation ( ) ;
2727 const authenticated = useSelector ( statusSelectors . authenticated ) ;
2828 const dispatch = useDispatch ( ) ;
@@ -31,7 +31,10 @@ export const LoginCallback = (): React.ReactElement => {
3131 const params = new URLSearchParams ( location . search ) ;
3232 const code = params . get ( "code" ) ;
3333 const state = params . get ( "state" ) ;
34+ const error = params . get ( "error" ) ;
35+ const errorDescription = params . get ( "error_description" ) ;
3436 const hasParams = Boolean ( code && state ) ;
37+ const hasError = Boolean ( error || errorDescription ) ;
3538
3639 const callback = useGetCallback (
3740 {
@@ -45,7 +48,7 @@ export const LoginCallback = (): React.ReactElement => {
4548
4649 const hasHandledSuccess = useRef ( false ) ;
4750 const shouldShowMissingParamsError =
48- ! authenticated && ! hasParams && ! callback . isError ;
51+ ! authenticated && ! hasParams && ! callback . isError && ! hasError ;
4952
5053 useEffect ( ( ) => {
5154 if ( authenticated ) {
@@ -70,17 +73,28 @@ export const LoginCallback = (): React.ReactElement => {
7073 < Strip >
7174 < Row >
7275 < Col emptyLarge = { 4 } size = { 6 } >
76+ { hasError && (
77+ < Notification role = "alert" severity = "negative" >
78+ { error && `Error: ${ error } . ` }
79+ < br />
80+ { errorDescription }
81+ < br />
82+ Please try < Link to = { urls . login } > logging in</ Link > again.
83+ </ Notification >
84+ ) }
7385 { shouldShowMissingParamsError && (
7486 < Notification role = "alert" severity = "information" >
7587 { Labels . MissingParams }
7688 </ Notification >
7789 ) }
78- { code && state && callback . isPending && (
90+ { code && state && ! hasError && callback . isPending && (
7991 < Spinner aria-label = { "Loading..." } text = "Loading..." />
8092 ) }
8193 { callback . isError && (
8294 < Notification role = "alert" severity = "negative" >
8395 { Labels . CallbackError }
96+ < br />
97+ Please try < Link to = { urls . login } > logging in</ Link > again.
8498 </ Notification >
8599 ) }
86100 { authenticated && (
0 commit comments