Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
dragoni7 committed Jul 10, 2024
1 parent 8738153 commit 5282dbe
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 137 deletions.
2 changes: 1 addition & 1 deletion src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { RouterProvider } from "react-router-dom";
import { useMemo } from "react";
import { createRouter } from "./routes";
import { Provider } from "react-redux";
import { store } from "../redux";
import { store } from "../store";

const AppRouter = () => {
const router = useMemo(() => createRouter(), []);
Expand Down
8 changes: 0 additions & 8 deletions src/app/routes/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ import { styled } from "@mui/system";
import SingleDiamondButton from "../../components/SingleDiamondButton";
import NumberBoxes from "../../components/NumberBoxes";
import StatsTable from "../../components/StatsTable";
import { getCurrentMembershipData } from "../../features/membership/BungieAccount";
import { useEffect } from "react";
import { getProfile } from "../../features/profile/DestinyProfile";

// import React from 'react';
// import './App.css';
Expand Down Expand Up @@ -57,11 +54,6 @@ const RightPane = styled("div")({
});

export const Dashboard = () => {
useEffect(() => {
//getCurrentMembershipData();
//getProfile(localStorage.getItem("primaryMembershipId") as string);
}, []);

return (
<Container>
<div>{localStorage.getItem("profile")}</div>
Expand Down
10 changes: 4 additions & 6 deletions src/app/routes/Landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { regenerateTokens } from "../../lib/bungie_api/TokenService";
import { isAuthenticated } from "../../lib/bungie_api/AuthService";
import { Container, Grid, Paper } from "@mui/material";
import { useDispatch } from "react-redux";
import { updateMembershipId } from "../../redux/MembershipReducer";
import { getCurrentMembershipData } from "../../features/membership/BungieAccount";
import { updateMembershipId } from "../../store/MembershipReducer";
import { getDestinyMembershipId } from "../../features/membership/BungieAccount";

export const LandingRoute = () => {
const navigate = useNavigate();
Expand All @@ -17,15 +17,13 @@ export const LandingRoute = () => {
setTimeout(async () => {
if (isAuthenticated()) {
console.log("Already authenticated");
var destinyMembershipId = await getCurrentMembershipData();
console.log(destinyMembershipId);
var destinyMembershipId = await getDestinyMembershipId();
dispatch(updateMembershipId(destinyMembershipId));

navigate("/app");
} else if (regenerateTokens()) {
console.log("Tokens regenerated and authenticated");
var destinyMembershipId = await getCurrentMembershipData();
console.log(destinyMembershipId);
var destinyMembershipId = await getDestinyMembershipId();
dispatch(updateMembershipId(destinyMembershipId));
navigate("/app");
} else {
Expand Down
31 changes: 12 additions & 19 deletions src/app/routes/Return.tsx
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>;
};
56 changes: 28 additions & 28 deletions src/app/routes/index.tsx
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>
),
},
]);
};
37 changes: 18 additions & 19 deletions src/features/auth/AuthReturn.tsx
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;
}
17 changes: 8 additions & 9 deletions src/features/auth/BungieLogin.tsx
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;
2 changes: 1 addition & 1 deletion src/features/membership/BungieAccount.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { _get } from "../../lib/bungie_api/BungieApiClient";
import { getMembershipId, getTokens } from "../../lib/bungie_api/TokensStore";

export async function getCurrentMembershipData(): Promise<string> {
export async function getDestinyMembershipId(): Promise<string> {
const membershipId = getMembershipId();
const accessToken = getTokens()?.accessToken.value;

Expand Down
89 changes: 43 additions & 46 deletions src/features/profile/DestinyProfile.ts
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.

0 comments on commit 5282dbe

Please sign in to comment.