From 82bcf75179f68d9489b63b5c0e60100c8fb09550 Mon Sep 17 00:00:00 2001 From: Chris Miller Date: Wed, 10 Jan 2024 23:58:50 -0500 Subject: [PATCH] fix up flow --- api/src/users/user.entity.ts | 2 +- frontend/src/contexts/AuthContext.tsx | 14 ++++++++++++-- frontend/src/pages/UserUpdate.tsx | 12 +++++++++--- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/api/src/users/user.entity.ts b/api/src/users/user.entity.ts index bf318c95..b5e4e50c 100644 --- a/api/src/users/user.entity.ts +++ b/api/src/users/user.entity.ts @@ -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 { diff --git a/frontend/src/contexts/AuthContext.tsx b/frontend/src/contexts/AuthContext.tsx index cd9da27d..68fad732 100644 --- a/frontend/src/contexts/AuthContext.tsx +++ b/frontend/src/contexts/AuthContext.tsx @@ -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); @@ -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); diff --git a/frontend/src/pages/UserUpdate.tsx b/frontend/src/pages/UserUpdate.tsx index a3ff6767..6c1a2375 100644 --- a/frontend/src/pages/UserUpdate.tsx +++ b/frontend/src/pages/UserUpdate.tsx @@ -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, ); @@ -76,6 +76,10 @@ export function UserUpdate() { const allowUserEdit = canEdit(profile, user?.username); + useEffect(() => { + reloadAuthState(); + }, []); + useEffect(() => { if (description === undefined && user.description) { setDescription(user.description ?? ''); @@ -172,10 +176,12 @@ export function UserUpdate() {

Connections

beginMsFlow()} onDisconnect={() => alert('Unimplemented')} />