Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚡fixes #746 App takes you to login screen after being logged in for a while #817

Merged
merged 5 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions packages/app/components/authorization/CheckAuthorization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { apiUrl } from '@/lib/utils/utils';
import { cookies } from 'next/headers';

const CheckAuthorization = async () => {
const privyToken = cookies().get('privy-token');
const userSession = cookies().get('user-session');
const userAddress = cookies().get('user-address');
const res = await fetch(`${apiUrl()}/auth/verify-token`, {
Expand All @@ -14,12 +13,8 @@ const CheckAuthorization = async () => {
headers: { 'Content-Type': 'application/json' },
});
const resData = await res.json();

const isAuthorized =
!!userAddress?.value &&
!!privyToken?.value &&
!!userSession?.value &&
resData.data;
!!userAddress?.value && !!userSession?.value && resData.data;

return isAuthorized;
};
Expand Down
17 changes: 16 additions & 1 deletion packages/app/components/misc/SignInUserButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useLogin, useLogout, usePrivy } from '@privy-io/react-auth';
import { deleteSession, storeSession } from '@/lib/actions/auth';
import { apiUrl } from '@/lib/utils/utils';
import { Loader2 } from 'lucide-react';
import { useState } from 'react';
import React, { useEffect, useState } from 'react';

interface SignInUserButtonProps {
className?: string;
Expand All @@ -18,6 +18,11 @@ export const SignInUserButton = ({
const { ready, authenticated } = usePrivy();
const [isLoading, setIsLoading] = useState(false);

const privyRefreshToken = localStorage.getItem('privy:refresh_token');
const parsePrivyRefreshToken = privyRefreshToken
? JSON.parse(privyRefreshToken)
: null;

const getSession = async () => {
const privyToken = localStorage.getItem('privy:token');
const token = privyToken ? JSON.parse(privyToken) : null;
Expand All @@ -36,6 +41,16 @@ export const SignInUserButton = ({
});
};

useEffect(() => {
if (!parsePrivyRefreshToken) logout();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [parsePrivyRefreshToken]);

useEffect(() => {
if (!parsePrivyRefreshToken) logout();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [parsePrivyRefreshToken]);

const { login } = useLogin({
onComplete: () => {
getSession();
Expand Down
4 changes: 2 additions & 2 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@livekit/components-react": "^1.5.3",
"@livekit/components-styles": "^1.0.9",
"@livepeer/react": "^4.1.8",
"@privy-io/react-auth": "^1.64.0",
"@privy-io/react-auth": "^1.76.2",
"@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-alert-dialog": "^1.0.5",
"@radix-ui/react-aspect-ratio": "^1.0.3",
Expand Down Expand Up @@ -97,9 +97,9 @@
"zod": "^3.22.4"
},
"devDependencies": {
"@types/lodash": "^4.17.7",
"@tailwindcss/typography": "^0.5.13",
"@types/fuzzy-search": "^2.1.5",
"@types/lodash": "^4.17.7",
"@types/node": "20.14.11",
"@types/react": "18.2.37",
"@types/react-color": "^3.0.11",
Expand Down
Loading