@@ -21,7 +21,7 @@ export class AgoraCallback extends AbstractController<RequestType> {
2121 public static readonly schema : FastifySchema < RequestType > = {
2222 querystring : {
2323 type : "object" ,
24- required : [ "state" , "code" , "loginId" ] ,
24+ required : [ "state" , "code" ] ,
2525 properties : {
2626 state : {
2727 type : "string" ,
@@ -30,19 +30,12 @@ export class AgoraCallback extends AbstractController<RequestType> {
3030 code : {
3131 type : "string" ,
3232 } ,
33- loginId : {
34- type : "string" ,
35- } ,
3633 } ,
3734 } ,
3835 } ;
3936
4037 public async execute ( ) : Promise < void > {
41- void this . reply . headers ( {
42- "content-type" : "text/html" ,
43- } ) ;
44-
45- const { state : authUUID , code, loginId : loginID } = this . querystring ;
38+ const { state : authUUID , code } = this . querystring ;
4639
4740 await LoginAgora . assertHasAuthUUID ( authUUID , this . logger ) ;
4841
@@ -67,71 +60,46 @@ export class AgoraCallback extends AbstractController<RequestType> {
6760 } ) ;
6861 }
6962
70- const { userName, avatarURL } = ( await loginAgora . svc . user . nameAndAvatar ( ) ) ! ;
71-
72- await loginAgora . tempSaveUserInfo ( authUUID , {
73- name : userName ,
74- token : await this . reply . jwtSign ( {
75- userUUID,
76- loginSource : LoginPlatform . Agora ,
77- } ) ,
78- avatar : avatarURL ,
79- agoraSSOLoginID : loginID ,
63+ const token = await this . reply . jwtSign ( {
64+ userUUID,
65+ loginSource : LoginPlatform . Agora ,
8066 } ) ;
8167
82- return this . reply . send ( AgoraCallback . successHTML ( ) ) ;
68+ void this . reply . redirect ( ` ${ Website } /login?token= ${ token } ` ) ;
8369 }
8470
8571 public async errorHandler ( error : Error ) : Promise < ResponseError > {
8672 await redisService . set ( RedisKey . authFailed ( this . querystring . state ) , error . message , 60 * 60 ) ;
8773
8874 this . logger . error ( "request failed" , parseError ( error ) ) ;
75+
76+ void this . reply . headers ( {
77+ "content-type" : "text/html" ,
78+ } ) ;
8979 return this . reply . send ( AgoraCallback . failedHTML ) ;
9080 }
9181
92- private static successHTML ( ) : string {
82+ private static get failedHTML ( ) : string {
9383 return `<!doctype html>
9484 <html lang="en">
9585 <head>
9686 <meta charset="UTF-8">
97- <title>Login Success </title>
87+ <title>Login Failed </title>
9888 </head>
9989 <body>
10090 <svg style=max-width:80px;max-height:80px;position:fixed;top:50%;left:50%;transform:translate(-50%,-50%) viewBox="0 0 80 80" xmlns="http://www.w3.org/2000/svg">
101- <path d="M40 0c22.0914 0 40 17.9086 40 40S62.0914 80 40 80 0 62.0914 0 40 17.9086 0 40 0zm0 4C20.1177 4 4 20.1177 4 40s16.1177 36 36 36 36-16.1177 36-36S59.8823 4 40 4zm22.6337 20.5395l2.7326 2.921-32.3889 30.2993L14.61 40.0046l2.78-2.876L33.022 52.24l29.6117-27.7005z " fill="#9FDF76 " fill-rule="nonzero" />
91+ <path d="M40 0c22.0914 0 40 17.9086 40 40S62.0914 80 40 80 0 62.0914 0 40 17.9086 0 40 0zm0 4C20.1177 4 4 20.1177 4 40s16.1177 36 36 36 36-16.1177 36-36S59.8823 4 40 4zm21.0572 49.2345l.357.3513-2.8284 2.8284c-10.162-10.162-26.5747-10.2636-36.8617-.3048l-.3099.3048-2.8284-2.8284c11.7085-11.7085 30.619-11.8256 42.4714-.3513zM27 26c2.2091 0 4 1.7909 4 4 0 2.2091-1.7909 4-4 4-2.2091 0-4-1.7909-4-4 0-2.2091 1.7909-4 4-4zm26 0c2.2091 0 4 1.7909 4 4 0 2.2091-1.7909 4-4 4-2.2091 0-4-1.7909-4-4 0-2.2091 1.7909-4 4-4z " fill="#F45454 " fill-rule="nonzero" />
10292 </svg>
103- <div id="text" style=position:fixed;top:60%;left:50%;transform:translate(-50%,-50%)>Login Success. After 3s it will automatically jump to the home page</div>
104- </body>
93+ <div id="text" style=position:fixed;top:60%;left:50%;transform:translate(-50%,-50%)>Login Failed. After 3s it will automatically jump to the home page</div>
10594 <script>
10695 if (navigator.language.startsWith("zh")) {
107- document.getElementById("text").textContent = "登录成功 ,3秒后将自动跳转到首页"
96+ document.getElementById("text").textContent = "登录失败 ,3秒后将自动跳转到首页"
10897 }
10998
11099 setTimeout(() => {
111100 location.href = "${ Website } ";
112101 }, 3000);
113102 </script>
114- </html>
115- ` ;
116- }
117-
118- private static get failedHTML ( ) : string {
119- return `<!doctype html>
120- <html lang="en">
121- <head>
122- <meta charset="UTF-8">
123- <title>Login Failed</title>
124- </head>
125- <body>
126- <svg style=max-width:80px;max-height:80px;position:fixed;top:50%;left:50%;transform:translate(-50%,-50%) viewBox="0 0 80 80" xmlns="http://www.w3.org/2000/svg">
127- <path d="M40 0c22.0914 0 40 17.9086 40 40S62.0914 80 40 80 0 62.0914 0 40 17.9086 0 40 0zm0 4C20.1177 4 4 20.1177 4 40s16.1177 36 36 36 36-16.1177 36-36S59.8823 4 40 4zm21.0572 49.2345l.357.3513-2.8284 2.8284c-10.162-10.162-26.5747-10.2636-36.8617-.3048l-.3099.3048-2.8284-2.8284c11.7085-11.7085 30.619-11.8256 42.4714-.3513zM27 26c2.2091 0 4 1.7909 4 4 0 2.2091-1.7909 4-4 4-2.2091 0-4-1.7909-4-4 0-2.2091 1.7909-4 4-4zm26 0c2.2091 0 4 1.7909 4 4 0 2.2091-1.7909 4-4 4-2.2091 0-4-1.7909-4-4 0-2.2091 1.7909-4 4-4z" fill="#F45454" fill-rule="nonzero" />
128- </svg>
129- <div id="text" style=position:fixed;top:60%;left:50%;transform:translate(-50%,-50%)>Login Failed</div>
130- <script>
131- if (navigator.language.startsWith("zh")) {
132- document.getElementById("text").textContent = "登录失败"
133- }
134- </script>
135103 </body>
136104 </html>
137105 ` ;
@@ -142,6 +110,5 @@ interface RequestType {
142110 querystring : {
143111 state : string ;
144112 code : string ;
145- loginId : string ;
146113 } ;
147114}
0 commit comments