Skip to content

Commit

Permalink
✨ improve redirect on login
Browse files Browse the repository at this point in the history
  • Loading branch information
pouyio committed Feb 5, 2024
1 parent a959c6e commit 0b37ee0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/components/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ const Login: React.FC<ILoginProps> = ({ code }) => {
useEffect(() => {
loginApi(code).then(({ data }) => {
authService.session = data;
history('/movies');
const redirectPath = localStorage.getItem('redirect_path');
if (redirectPath) {
localStorage.removeItem('redirect_path');
history(redirectPath);
} else {
history('/movies');
}
});
});

Expand Down
10 changes: 9 additions & 1 deletion src/components/LoginButton.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import React from 'react';
import { useLocation } from 'react-router-dom';
const redirect_url = import.meta.env.VITE_REDIRECT_URL;

export const LoginButton: React.FC<{ small?: boolean }> = ({ small }) => {
const location = useLocation();

const onClick = () => {
localStorage.setItem('redirect_path', location.pathname);
};

return (
<a
className={`bg-gray-400 rounded-full text-white ${
className={`bg-gray-400 cursor-pointer rounded-full text-white ${
small ? 'p-2' : 'px-12 py-3'
}`}
style={{ lineHeight: '2em' }}
onClick={onClick}
href={`https://trakt.tv/oauth/authorize?response_type=code&client_id=61afe7ed7ef7a2b6b2193254dd1cca580ba8dee91490df454d78fd68aed7e5f9&redirect_uri=${redirect_url}`}
>
Login
Expand Down

0 comments on commit 0b37ee0

Please sign in to comment.