Bladeren bron

use the new login function

Sven Czarnian 2 jaren geleden
bovenliggende
commit
ac257d1d2e
2 gewijzigde bestanden met toevoegingen van 14 en 14 verwijderingen
  1. 2 14
      src/components/login.tsx
  2. 12 0
      src/services/auth.ts

+ 2 - 14
src/components/login.tsx

@@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react';
 import { Button } from 'primereact/button';
 import { Card } from 'primereact/card';
 import { useNavigate } from 'react-router-dom';
-import { Auth, Configuration, Session } from '../services';
+import { Auth, Session } from '../services';
 import { BackendReturnStatus } from '../types';
 
 export const Login: React.FC = () => {
@@ -24,24 +24,12 @@ export const Login: React.FC = () => {
 
   if (loading) return <></>;
 
-  const redirectToVatsim = () => {
-    const url = [
-      Configuration.vatsim.authorizeUrl,
-      `?client_id=${Configuration.vatsim.clientId}`,
-      `&redirect_uri=${Configuration.resourceServer}/auth/vatsim`,
-      `&response_type=code`,
-      `&scope=full_name+vatsim_details`,
-      `&approval_prompt=auto`,
-    ].join('');
-    window.location.replace(url);
-  }
-
   const footer = (
     <span>
       <Button
         label='Login with VATSIM'
         className='p-button'
-        onClick={redirectToVatsim}
+        onClick={() => Auth.triggerLoginFlow()}
       />
     </span>
   );

+ 12 - 0
src/services/auth.ts

@@ -9,6 +9,18 @@ import {
 } from '../types';
 
 export class Auth {
+  static triggerLoginFlow(): void {
+    const url = [
+      Configuration.vatsim.authorizeUrl,
+      `?client_id=${Configuration.vatsim.clientId}`,
+      `&redirect_uri=${Configuration.resourceServer}/auth/vatsim`,
+      `&response_type=code`,
+      `&scope=full_name+vatsim_details`,
+      `&approval_prompt=auto`,
+    ].join('');
+    window.location.replace(url);
+  }
+
   static async tokenIsValid(): Promise<BackendReturnStatus> {
     const token = Session.bearerToken();
     if (!token) return BackendReturnStatus.Unauthorized;