Skip to content

Commit

Permalink
fix up flow
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherJMiller committed Jan 11, 2024
1 parent a832107 commit 82bcf75
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api/src/users/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class User {
groups: Group[];

@OneToOne(() => Connection)
@JoinColumn({ name: 'userId' })
@JoinColumn({ name: 'id', referencedColumnName: 'userId' })
connections?: Connection;

static fromJwt(jwt: ReallianceIdJwt): User {
Expand Down
14 changes: 12 additions & 2 deletions frontend/src/contexts/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,20 @@ export function AuthContextProvider({ children }: ContextProps) {
console.log('Getting profile claims');
const run = async () => {
const now = Date.now();
const { data, error } = await getProfile(token);
const resp = await getProfile(token);
const error = resp.error;
let data = resp.data;

if (error) {
console.error(error);
return;
}

// On first load data can sometimes not exist, double check
if (data?.id === undefined) {
data = (await getProfile(token)).data;
}

const diff = Date.now() - now;
const minWait = MIN_WAIT_MS - diff;
const wait = Math.max(0, minWait);
Expand All @@ -88,7 +95,10 @@ export function AuthContextProvider({ children }: ContextProps) {
profile,
token,
loading,
reloadAuthState: () => setLoading(true),
reloadAuthState: () => {
setLoading(true);
setProfile(undefined);
},
updateToken: (token) => {
setLoading(true);
setToken(token);
Expand Down
12 changes: 9 additions & 3 deletions frontend/src/pages/UserUpdate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ interface EventTargets {
}

export function UserUpdate() {
const { loading, profile, token } = useContext(AuthContext);
const { loading, profile, token, reloadAuthState } = useContext(AuthContext);
const minecraftContext = useMinecraftContext(
profile?.connections?.minecraft_uuid,
);
Expand All @@ -76,6 +76,10 @@ export function UserUpdate() {

const allowUserEdit = canEdit(profile, user?.username);

useEffect(() => {
reloadAuthState();
}, []);

useEffect(() => {
if (description === undefined && user.description) {
setDescription(user.description ?? '');
Expand Down Expand Up @@ -172,10 +176,12 @@ export function UserUpdate() {
<hr />
<h1 className="text-2xl">Connections</h1>
<ConnectionCard
title={`Minecraft ${minecraftSubtitle && '- ' + minecraftSubtitle}`}
title={`Minecraft${
minecraftSubtitle ? ` - ${minecraftSubtitle}` : ''
}`}
description="Connect your Microsoft account to enlist your Minecraft user for future sevres."
avatarImage={minecraftContext?.avatar}
connected={profile?.connections?.minecraft_uuid !== undefined}
connected={profile?.connections?.minecraft_uuid !== null}
onConnect={() => beginMsFlow()}
onDisconnect={() => alert('Unimplemented')}
/>
Expand Down

0 comments on commit 82bcf75

Please sign in to comment.