fix: first time you log in you are never considered as admin

Massimo Melina committed Jul 26, 2022 at 15:07 UTC 1808faf39cfd5b3b2e2b0b39f8ac0a1c63ed1953
1 file changed +4 -4
server/src/api.auth.ts
+4 -4
@@ -15,7 +15,7 @@ const srp6aNimbusRoutines = new SRPRoutines(new SRPParameters())
15 const ongoingLogins:Record<string,SRPServerSessionStep1> = {} // store data that doesn't fit session object
16
17 // centralized log-in state
18 -function loggedIn(ctx:Koa.Context, username: string | false) {
18 +async function loggedIn(ctx:Koa.Context, username: string | false) {
19 const s = ctx.session
20 if (!s)
21 return ctx.throw(500,'session')
@@ -25,7 +25,7 @@ function loggedIn(ctx:Koa.Context, username: string | false) {
25 return
26 }
27 s.username = username
28 - prepareState(ctx, async ()=>{}) // updating the state is necessary to send complete session data so that frontend shows admin button
28 + await prepareState(ctx, async ()=>{}) // updating the state is necessary to send complete session data so that frontend shows admin button
29 delete s.login
30 ctx.cookies.set('csrf', randomId(), { signed:false, httpOnly: false })
31 }
@@ -47,7 +47,7 @@ export const login: ApiHandler = async ({ username, password }, ctx) => {
47 return new ApiError(UNAUTHORIZED)
48 if (!ctx.session)
49 return new ApiError(500)
50 - loggedIn(ctx, username)
50 + await loggedIn(ctx, username)
51 return { ...makeExp(), redirect: acc.redirect }
52 }
53
@@ -91,7 +91,7 @@ export const loginSrp2: ApiHandler = async ({ pubKey, proof }, ctx) => {
91 const step1 = ongoingLogins[sid]
92 try {
93 const M2 = await step1.step2(BigInt(pubKey), BigInt(proof))
94 - loggedIn(ctx, username)
94 + await loggedIn(ctx, username)
95 return {
96 proof: String(M2),
97 redirect: ctx.state.account?.redirect,