account.redirect
Massimo Melina committed
Jan 13, 2022 at 00:11 UTC
f8b3bc5c5e51a926471ca5d2ab8e582a9458ea83
6 files changed
+11
-4
README.md
+1
@@ -94,6 +94,7 @@ gather multiple accounts and refer to them collectively as `group1`, so you can
94
Other options you can define as properties of an account:
95
96
- `ignore_limits` to ignore speed limits. Default is `false`.
97
+- `redirect` provide a URL if you want the user to be redirected upon login. Default is none.
98
99
# Building instructions
100
frontend/src/login.ts
+1
@@ -35,6 +35,7 @@ export async function login(username:string, password:string) {
35
// login was successful, update state
36
sessionRefresher({ username, exp:res.exp })
37
state.username = username
38
+ return res
39
}
40
catch(err) {
41
stopWorking()
frontend/src/menu.ts
+5
-1
@@ -6,6 +6,7 @@ import { hIcon, prefix } from './misc'
6
import { login } from './login'
7
import { showOptions } from './options'
8
import showUserPanel from './UserPanel'
9
+import { useNavigate } from 'react-router-dom'
10
11
export function MenuPanel() {
12
const { remoteSearch, stopSearch, stoppedSearch, listFilter } = useSnapState()
@@ -98,6 +99,7 @@ export function MenuButton({ icon, label, toggled, onClick, className = '' }: Me
99
100
function LoginButton() {
101
const snap = useSnapState()
102
+ const navigate = useNavigate()
103
return MenuButton(snap.username ? {
104
icon: 'user',
105
label: snap.username,
@@ -110,7 +112,9 @@ function LoginButton() {
112
if (!user) return
113
const password = await promptDialog('Password', { type: 'password' })
114
if (!password) return
113
- await login(user, password)
115
+ const res = await login(user, password)
116
+ if (res.redirect)
117
+ navigate(res.redirect)
118
}
119
})
120
}
src/api.auth.ts
+3
-2
@@ -45,7 +45,7 @@ export const login: ApiHandler = async ({ username, password }, ctx) => {
45
if (!ctx.session)
46
return new ApiError(500)
47
loggedIn(ctx, username)
48
- return makeExp()
48
+ return { ...makeExp(), redirect: acc.redirect }
49
}
50
51
export const loginSrp1: ApiHandler = async ({ username }, ctx) => {
@@ -78,7 +78,8 @@ export const loginSrp2: ApiHandler = async ({ pubKey, proof }, ctx) => {
78
try {
79
const M2 = await step1.step2(BigInt(pubKey), BigInt(proof))
80
loggedIn(ctx, username)
81
- return { proof: String(M2), ...makeExp() }
81
+ const acc = getAccount(username)
82
+ return { proof: String(M2), redirect: acc?.redirect, ...makeExp() }
83
}
84
catch(e) {
85
return new ApiError(401, String(e))
src/perm.ts
+1
@@ -17,6 +17,7 @@ interface Account {
17
srp?: string
18
belongs?: string[]
19
ignore_limits?: boolean
20
+ redirect?: string
21
}
22
interface Accounts { [username:string]: Account }
23
todo.md
-1
@@ -8,7 +8,6 @@
8
- search and login dialogs should push to history so that mobile can use back button to close them
9
- node.comment
10
- config: max connections (total/per-ip)
11
-- account.redirect
11
- config: bans
12
- config: min disk space
13
- thumbnails support