-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
115 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,19 @@ | ||
import { useEffect } from "react" | ||
import { useNavigate } from "react-router-dom" | ||
import { handleAuthReturn } from "../../features/auth/AuthReturn" | ||
import { useEffect } from "react"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { handleAuthReturn } from "../../features/auth/AuthReturn"; | ||
|
||
/** | ||
* Bungie OAuth redirects here | ||
*/ | ||
export const ReturnRoute = () => { | ||
const navigate = useNavigate(); | ||
|
||
const navigate = useNavigate() | ||
useEffect(() => { | ||
if (handleAuthReturn()) { | ||
// exit component if successful | ||
navigate("/"); | ||
} | ||
}, []); | ||
|
||
useEffect( () => { | ||
|
||
if (handleAuthReturn()) { | ||
// exit component if successful | ||
navigate('/') | ||
} | ||
|
||
}, []) | ||
|
||
return ( | ||
<div> | ||
Authentication Error | ||
</div> | ||
) | ||
} | ||
return <div>Authentication Error</div>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
import { createBrowserRouter } from 'react-router-dom'; | ||
import { Dashboard } from './Dashboard'; | ||
import { ProtectedRoute } from '../../lib/bungie_api/AuthService'; | ||
import { createBrowserRouter } from "react-router-dom"; | ||
import { Dashboard } from "./Dashboard"; | ||
import { ProtectedRoute } from "../../lib/bungie_api/AuthService"; | ||
|
||
export const createRouter = () => { | ||
return createBrowserRouter ([ | ||
{ | ||
path: '/', | ||
lazy: async () => { | ||
const { LandingRoute } = await import ('./Landing') | ||
return { Component: LandingRoute } | ||
} | ||
}, | ||
{ | ||
path: '/return', | ||
lazy: async () => { | ||
const { ReturnRoute } = await import ('./Return') | ||
return { Component: ReturnRoute } | ||
} | ||
}, | ||
{ | ||
path: '/app', | ||
element: ( | ||
<ProtectedRoute> | ||
<Dashboard /> | ||
</ProtectedRoute> | ||
) | ||
} | ||
]) | ||
} | ||
return createBrowserRouter([ | ||
{ | ||
path: "/", | ||
lazy: async () => { | ||
const { LandingRoute } = await import("./Landing"); | ||
return { Component: LandingRoute }; | ||
}, | ||
}, | ||
{ | ||
path: "/return", | ||
lazy: async () => { | ||
const { ReturnRoute } = await import("./Return"); | ||
return { Component: ReturnRoute }; | ||
}, | ||
}, | ||
{ | ||
path: "/app", | ||
element: ( | ||
<ProtectedRoute> | ||
<Dashboard /> | ||
</ProtectedRoute> | ||
), | ||
}, | ||
]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,31 @@ | ||
import { generateToken } from "../../lib/bungie_api/TokenService" | ||
import { setTokens } from "../../lib/bungie_api/TokensStore" | ||
import { generateToken } from "../../lib/bungie_api/TokenService"; | ||
|
||
function getAuthCodeFromURL(): string | null { | ||
return window.location.href.includes("code=") ? window.location.href.split('code=')[1] : null | ||
return window.location.href.includes("code=") | ||
? window.location.href.split("code=")[1] | ||
: null; | ||
} | ||
|
||
/** | ||
* Get auth tokens from auth code | ||
* @returns whether or not tokens were successfully generated | ||
*/ | ||
export function handleAuthReturn(): boolean { | ||
const code = getAuthCodeFromURL(); | ||
|
||
const code = getAuthCodeFromURL() | ||
console.log("auth code is " + code); | ||
|
||
console.log("auth code is " + code) | ||
if (!code?.length) { | ||
console.log("Could not find authorization code"); | ||
return false; | ||
} | ||
|
||
if (!code?.length) { | ||
console.log("Could not find authorization code") | ||
return false | ||
} | ||
try { | ||
generateToken(false, code); | ||
} catch (error) { | ||
console.log(error); | ||
return false; | ||
} | ||
|
||
try { | ||
generateToken(false, code) | ||
} | ||
catch (error) { | ||
console.log(error) | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
import React from "react" | ||
import { authenticate } from "../../lib/bungie_api/AuthService" | ||
import React from "react"; | ||
import { authenticate } from "../../lib/bungie_api/AuthService"; | ||
|
||
const BungieLogin: React.FC = () => { | ||
function onLogIn() { | ||
authenticate(); | ||
} | ||
|
||
function onLogIn () { | ||
authenticate() | ||
} | ||
return <button onClick={onLogIn}>Authorize with Bungie.net</button>; | ||
}; | ||
|
||
return ( <button onClick={onLogIn}>Authorize with Bungie.net</button> ) | ||
} | ||
|
||
export default BungieLogin | ||
export default BungieLogin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,49 @@ | ||
import { _get } from "../../lib/bungie_api/BungieApiClient" | ||
import { getTokens } from "../../lib/bungie_api/TokensStore" | ||
|
||
export interface DestinyCharacter{ | ||
membershipId:string | ||
membershipType: number | ||
characterId: string | ||
dateLastPlayed: string | ||
classType:number | ||
classHash:number | ||
emblemPath:string | ||
emblemHash:number | ||
emblemBackgroundPath: string | ||
import { _get } from "../../lib/bungie_api/BungieApiClient"; | ||
import { getTokens } from "../../lib/bungie_api/TokensStore"; | ||
|
||
export interface DestinyCharacter { | ||
membershipId: string; | ||
membershipType: number; | ||
characterId: string; | ||
dateLastPlayed: string; | ||
classType: number; | ||
classHash: number; | ||
emblemPath: string; | ||
emblemHash: number; | ||
emblemBackgroundPath: string; | ||
} | ||
|
||
export function getProfile(destinyMembershipId: string) { | ||
const accessToken = getTokens()?.accessToken; | ||
|
||
const accessToken = getTokens()?.accessToken | ||
|
||
_get(`/Platform/Destiny2/1/Profile/${destinyMembershipId}/?components=102,200`, { | ||
headers: { | ||
'Authorization': `Bearer ${accessToken}}` | ||
} | ||
}) | ||
.then(response => { | ||
if (response.data.Response) { | ||
_get( | ||
`/Platform/Destiny2/1/Profile/${destinyMembershipId}/?components=102,200`, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${accessToken}}`, | ||
}, | ||
} | ||
).then((response) => { | ||
if (response.data.Response) { | ||
var characters = response.data.Response.characters.data; | ||
for (const key in characters) { | ||
const character: DestinyCharacter = { | ||
membershipId: characters[key].membershipId, | ||
membershipType: characters[key].membershipType, | ||
characterId: characters[key].characterId, | ||
dateLastPlayed: characters[key].dateLastPlayed, | ||
classType: characters[key].classType, | ||
classHash: characters[key].classHash, | ||
emblemPath: characters[key].emblemPath, | ||
emblemHash: characters[key].emblemHash, | ||
emblemBackgroundPath: characters[key].emblemBackgroundPath, | ||
}; | ||
} | ||
|
||
var characters = response.data.Response.characters.data | ||
for(const key in characters) | ||
{ const character : DestinyCharacter = { | ||
membershipId:characters[key].membershipId, | ||
membershipType:characters[key].membershipType, | ||
characterId : characters[key].characterId, | ||
dateLastPlayed : characters[key].dateLastPlayed, | ||
classType : characters[key].classType, | ||
classHash : characters[key].classHash, | ||
emblemPath : characters[key].emblemPath, | ||
emblemHash : characters[key].emblemHash, | ||
emblemBackgroundPath:characters[key].emblemBackgroundPath | ||
} | ||
|
||
} | ||
|
||
return true | ||
} | ||
else { | ||
console.log("Could not get response") | ||
return false | ||
} | ||
}) | ||
} | ||
return true; | ||
} else { | ||
console.log("Could not get response"); | ||
return false; | ||
} | ||
}); | ||
} |
File renamed without changes.
File renamed without changes.