fix signup url
All checks were successful
Build and Push Docker Image / Build image (push) Successful in 1m31s
All checks were successful
Build and Push Docker Image / Build image (push) Successful in 1m31s
This commit is contained in:
parent
e81b7abd1a
commit
f8647c50ae
178
src/signup.tsx
178
src/signup.tsx
@ -6,101 +6,101 @@ import Cookies from 'js-cookie'
|
|||||||
import { fetchToken } from "./login";
|
import { fetchToken } from "./login";
|
||||||
|
|
||||||
const signUp = async (username: string, password: string, token: string) => {
|
const signUp = async (username: string, password: string, token: string) => {
|
||||||
try {
|
try {
|
||||||
const response = await api.post(`/signup?token=${token}`, {
|
const response = await api.post(`/auth/signup?token=${token}`, {
|
||||||
username: username,
|
username: username,
|
||||||
password: password,
|
password: password,
|
||||||
}, {
|
}, {
|
||||||
});
|
});
|
||||||
return response.data.access_token;
|
return response.data.access_token;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching token:', error);
|
console.error('Error fetching token:', error);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export function SignupPage(props: {}) {
|
export function SignupPage(props: {}) {
|
||||||
const [apiAuthenticated, setApiAuthenticated] = useContext(apiAuthenticatedContext)
|
const [apiAuthenticated, setApiAuthenticated] = useContext(apiAuthenticatedContext)
|
||||||
const [searchParam, setSearchParam] = useSearchParams();
|
const [searchParam, setSearchParam] = useSearchParams();
|
||||||
const token = searchParam.get('token');
|
const token = searchParam.get('token');
|
||||||
if (token === null){
|
if (token === null) {
|
||||||
return <Navigate to='/' />
|
return <Navigate to='/' />
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apiAuthenticated) {
|
||||||
|
return <Navigate to='/' />
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSubmit: FormEventHandler<HTMLFormElement> = (event: FormEvent<HTMLFormElement>) => {
|
||||||
|
event.preventDefault();
|
||||||
|
const data = new FormData(event.currentTarget);
|
||||||
|
const usernameFormData: FormDataEntryValue | null = data.get('username');
|
||||||
|
const passwordFormData: FormDataEntryValue | null = data.get('password');
|
||||||
|
if (usernameFormData === null || passwordFormData === null) {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
const username: string = usernameFormData.toString();
|
||||||
if (apiAuthenticated) {
|
const password: string = passwordFormData.toString();
|
||||||
return <Navigate to='/' />
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleSubmit: FormEventHandler<HTMLFormElement> = (event: FormEvent<HTMLFormElement>) => {
|
|
||||||
event.preventDefault();
|
|
||||||
const data = new FormData(event.currentTarget);
|
|
||||||
const usernameFormData: FormDataEntryValue | null = data.get('username');
|
|
||||||
const passwordFormData: FormDataEntryValue | null = data.get('password');
|
|
||||||
if (usernameFormData === null || passwordFormData === null){
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const username: string = usernameFormData.toString();
|
|
||||||
const password: string = passwordFormData.toString();
|
|
||||||
|
|
||||||
|
|
||||||
signUp(username, password, token).then(
|
signUp(username, password, token).then(
|
||||||
() => {
|
() => {
|
||||||
fetchToken(username, password, true).then(
|
fetchToken(username, password, true).then(
|
||||||
(token) => {
|
(token) => {
|
||||||
setApiAuthenticated(true)
|
setApiAuthenticated(true)
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
|
||||||
<Container component="main" maxWidth="xs">
|
|
||||||
<CssBaseline />
|
|
||||||
<Box
|
|
||||||
sx={{
|
|
||||||
marginTop: 8,
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
alignItems: 'center',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Typography component="h1" variant="h5">
|
|
||||||
Sign up
|
|
||||||
</Typography>
|
|
||||||
<Box component="form" onSubmit={handleSubmit} noValidate sx={{ mt: 1 }}>
|
|
||||||
<TextField
|
|
||||||
margin="normal"
|
|
||||||
required
|
|
||||||
fullWidth
|
|
||||||
id="username"
|
|
||||||
label="User Name"
|
|
||||||
name="username"
|
|
||||||
autoFocus
|
|
||||||
/>
|
|
||||||
<TextField
|
|
||||||
margin="normal"
|
|
||||||
required
|
|
||||||
fullWidth
|
|
||||||
name="password"
|
|
||||||
label="Password"
|
|
||||||
type="password"
|
|
||||||
id="password"
|
|
||||||
autoComplete="new-password"
|
|
||||||
/>
|
|
||||||
<Button
|
|
||||||
type="submit"
|
|
||||||
fullWidth
|
|
||||||
variant="contained"
|
|
||||||
sx={{ mt: 3, mb: 2 }}
|
|
||||||
>
|
|
||||||
Sign Up
|
|
||||||
</Button>
|
|
||||||
</Box>
|
|
||||||
</Box>
|
|
||||||
</Container>
|
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Container component="main" maxWidth="xs">
|
||||||
|
<CssBaseline />
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
marginTop: 8,
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
alignItems: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography component="h1" variant="h5">
|
||||||
|
Sign up
|
||||||
|
</Typography>
|
||||||
|
<Box component="form" onSubmit={handleSubmit} noValidate sx={{ mt: 1 }}>
|
||||||
|
<TextField
|
||||||
|
margin="normal"
|
||||||
|
required
|
||||||
|
fullWidth
|
||||||
|
id="username"
|
||||||
|
label="User Name"
|
||||||
|
name="username"
|
||||||
|
autoFocus
|
||||||
|
/>
|
||||||
|
<TextField
|
||||||
|
margin="normal"
|
||||||
|
required
|
||||||
|
fullWidth
|
||||||
|
name="password"
|
||||||
|
label="Password"
|
||||||
|
type="password"
|
||||||
|
id="password"
|
||||||
|
autoComplete="new-password"
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
type="submit"
|
||||||
|
fullWidth
|
||||||
|
variant="contained"
|
||||||
|
sx={{ mt: 3, mb: 2 }}
|
||||||
|
>
|
||||||
|
Sign Up
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
</Container>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user