login.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import React, { useEffect } from 'react';
  2. import { Button } from 'primereact/button';
  3. import { Card } from 'primereact/card';
  4. import { Configuration } from '../services';
  5. export const Login: React.FC = () => {
  6. // reset every old token
  7. useEffect(() => sessionStorage.removeItem('token'), []);
  8. const redirectToVatsim = () => {
  9. const url = [
  10. Configuration.vatsim.authorizeUrl,
  11. `?client_id=${Configuration.vatsim.clientId}`,
  12. `&redirect_uri=http://localhost:3000/auth/vatsim`,
  13. `&response_type=code`,
  14. `&scope=full_name+vatsim_details`,
  15. `&approval_prompt=auto`,
  16. ].join('');
  17. window.location.replace(url);
  18. }
  19. const footer = (
  20. <span>
  21. <Button
  22. label='Login with VATSIM SSO'
  23. className='p-button p-button-success'
  24. onClick={redirectToVatsim}
  25. />
  26. </span>
  27. );
  28. return (
  29. <>
  30. <Card
  31. title='Arrival MANager'
  32. className='login-card text-center surface-200'
  33. style={{ width: '25rem' }}
  34. footer={footer}>
  35. </Card>
  36. </>
  37. );
  38. };