use the new login function
This commit is contained in:
@@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react';
|
|||||||
import { Button } from 'primereact/button';
|
import { Button } from 'primereact/button';
|
||||||
import { Card } from 'primereact/card';
|
import { Card } from 'primereact/card';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { Auth, Configuration, Session } from '../services';
|
import { Auth, Session } from '../services';
|
||||||
import { BackendReturnStatus } from '../types';
|
import { BackendReturnStatus } from '../types';
|
||||||
|
|
||||||
export const Login: React.FC = () => {
|
export const Login: React.FC = () => {
|
||||||
@@ -24,24 +24,12 @@ export const Login: React.FC = () => {
|
|||||||
|
|
||||||
if (loading) return <></>;
|
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 = (
|
const footer = (
|
||||||
<span>
|
<span>
|
||||||
<Button
|
<Button
|
||||||
label='Login with VATSIM'
|
label='Login with VATSIM'
|
||||||
className='p-button'
|
className='p-button'
|
||||||
onClick={redirectToVatsim}
|
onClick={() => Auth.triggerLoginFlow()}
|
||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -9,6 +9,18 @@ import {
|
|||||||
} from '../types';
|
} from '../types';
|
||||||
|
|
||||||
export class Auth {
|
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> {
|
static async tokenIsValid(): Promise<BackendReturnStatus> {
|
||||||
const token = Session.bearerToken();
|
const token = Session.bearerToken();
|
||||||
if (!token) return BackendReturnStatus.Unauthorized;
|
if (!token) return BackendReturnStatus.Unauthorized;
|
||||||
|
|||||||
Reference in New Issue
Block a user