Skip to content

Commit

Permalink
fix: update seassion
Browse files Browse the repository at this point in the history
  • Loading branch information
irmannmal committed Mar 3, 2023
1 parent b380140 commit 1e5a358
Showing 22 changed files with 175 additions and 25 deletions.
14 changes: 14 additions & 0 deletions pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
@@ -119,6 +119,19 @@ const createOptions = (req: NextApiRequest) => ({
}
},
}),
CredentialsProvider({
id: 'updateSession',
// The name to display on the sign in form (e.g. 'Sign in with...')
name: 'Update Credential',
// The credentials is used to generate a suitable form on the sign in page.
// You can specify whatever fields you are expecting to be submitted.
// e.g. domain, username, password, 2FA token, etc.
credentials: {},
async authorize(credentials) {
// Initialize instance api url
return credentials;
},
}),
],
// Database optional. MySQL, Maria DB, Postgres and MongoDB are supported.
// https://next-auth.js.org/configuration/databases
@@ -206,6 +219,7 @@ const createOptions = (req: NextApiRequest) => ({
walletType: user.walletType,
networkType: user.networkType,
blockchainPlatform: user.blockchainPlatform,
gaga: user.gaga,
};
}

8 changes: 7 additions & 1 deletion pages/experience/[experienceId]/clone.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Sentry from '@sentry/nextjs';

import React from 'react';
import React, { useEffect } from 'react';

import { Session } from 'next-auth';
import { getSession } from 'next-auth/react';
@@ -10,6 +10,7 @@ import Head from 'next/head';
import { ExperienceCloneContainer } from 'src/components/ExperiencePreview/ExperienceClone.container';
import { DefaultLayout } from 'src/components/template/Default/DefaultLayout';
import { User } from 'src/interfaces/user';
import { updateSession } from 'src/lib/api/auth-link';
import { initialize } from 'src/lib/api/base';
import * as ExperienceAPI from 'src/lib/api/experience';
import { healthcheck } from 'src/lib/api/healthcheck';
@@ -35,6 +36,11 @@ type CloneExperiencePageProps = {
};

const CloneExperience: React.FC<CloneExperiencePageProps> = props => {
const { session } = props;
useEffect(() => {
if (!session?.user?.instanceURL) updateSession(session);
}, [session]);

return (
<DefaultLayout isOnProfilePage={false} {...props}>
<Head>
7 changes: 6 additions & 1 deletion pages/experience/[experienceId]/edit.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Sentry from '@sentry/nextjs';

import React from 'react';
import React, { useEffect } from 'react';

import { Session } from 'next-auth';
import { getSession } from 'next-auth/react';
@@ -10,6 +10,7 @@ import Head from 'next/head';
import { ExperienceEditContainer } from 'src/components/ExperiencePreview/ExperienceEdit.container';
import { DefaultLayout } from 'src/components/template/Default/DefaultLayout';
import { User } from 'src/interfaces/user';
import { updateSession } from 'src/lib/api/auth-link';
import { initialize } from 'src/lib/api/base';
import * as ExperienceAPI from 'src/lib/api/experience';
import { healthcheck } from 'src/lib/api/healthcheck';
@@ -36,6 +37,10 @@ type EditExperiencePageProps = {
};

const EditExperience: React.FC<EditExperiencePageProps> = props => {
const { session } = props;
useEffect(() => {
if (!session?.user?.instanceURL) updateSession(session);
}, [session]);
return (
<DefaultLayout isOnProfilePage={false} {...props}>
<Head>
8 changes: 6 additions & 2 deletions pages/experience/[experienceId]/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Sentry from '@sentry/nextjs';

import React from 'react';
import React, { useEffect } from 'react';

import { Session } from 'next-auth';
import { getSession } from 'next-auth/react';
@@ -16,6 +16,7 @@ import { ExperiencePreviewContainer } from 'src/components/ExperiencePreview/Exp
import { DefaultLayout } from 'src/components/template/Default/DefaultLayout';
import { generateAnonymousUser } from 'src/helpers/auth';
import { User } from 'src/interfaces/user';
import { updateSession } from 'src/lib/api/auth-link';
import { initialize } from 'src/lib/api/base';
import * as ExperienceAPI from 'src/lib/api/experience';
import { healthcheck } from 'src/lib/api/healthcheck';
@@ -47,7 +48,10 @@ type ExperiencePageProps = {
};

const PreviewExperience: React.FC<ExperiencePageProps> = props => {
const { title, image, description, hidden } = props;
const { title, image, description, hidden, session } = props;
useEffect(() => {
if (!session?.user?.instanceURL) updateSession(session);
}, [session]);

const router = useRouter();

7 changes: 6 additions & 1 deletion pages/experience/create.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect } from 'react';

import { Session } from 'next-auth';
import { getSession } from 'next-auth/react';
@@ -7,6 +7,7 @@ import Head from 'next/head';

import { ExperienceContainer } from 'src/components/ExperienceEditor/Experience.container';
import { DefaultLayout } from 'src/components/template/Default/DefaultLayout';
import { updateSession } from 'src/lib/api/auth-link';
import { initialize } from 'src/lib/api/base';
import { healthcheck } from 'src/lib/api/healthcheck';
import i18n from 'src/locale';
@@ -31,6 +32,10 @@ type CreateExperiencePageProps = {
};

const CreateExperience: React.FC<CreateExperiencePageProps> = props => {
const { session } = props;
useEffect(() => {
if (!session?.user?.instanceURL) updateSession(session);
}, [session]);
return (
<DefaultLayout isOnProfilePage={false} {...props}>
<Head>
7 changes: 6 additions & 1 deletion pages/experience/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect } from 'react';

import { Session } from 'next-auth';
import { getSession } from 'next-auth/react';
@@ -11,6 +11,7 @@ import {
SectionTitle,
} from 'src/components/atoms/TopNavbar';
import { DefaultLayout } from 'src/components/template/Default/DefaultLayout';
import { updateSession } from 'src/lib/api/auth-link';
import initialize from 'src/lib/api/base';
import { healthcheck } from 'src/lib/api/healthcheck';
import { fetchAvailableToken } from 'src/reducers/config/actions';
@@ -34,6 +35,10 @@ type ExperiencePageProps = {
};

const ExperiencePageComponent: React.FC<ExperiencePageProps> = props => {
const { session } = props;
useEffect(() => {
if (!session?.user?.instanceURL) updateSession(session);
}, [session]);
return (
<DefaultLayout isOnProfilePage={false} {...props}>
<Head>
8 changes: 7 additions & 1 deletion pages/experience/trending.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect } from 'react';

import { Session } from 'next-auth';
import { getSession } from 'next-auth/react';
@@ -9,6 +9,7 @@ import { ExperienceTab } from 'src/components/RightMenuBar/tabs/ExperienceTab';
import { TopNavbarComponent } from 'src/components/atoms/TopNavbar';
import { DefaultLayout } from 'src/components/template/Default/DefaultLayout';
import { useExperienceHook } from 'src/hooks/use-experience-hook';
import { updateSession } from 'src/lib/api/auth-link';
import initialize from 'src/lib/api/base';
import { healthcheck } from 'src/lib/api/healthcheck';
import i18n from 'src/locale';
@@ -34,6 +35,11 @@ type TrendingExperiencePageProps = {

const ExperiencePageComponent: React.FC<TrendingExperiencePageProps> =
props => {
const { session } = props;
useEffect(() => {
if (!session?.user?.instanceURL) updateSession(session);
}, [session]);

const { loadTrendingExperience } = useExperienceHook();

React.useEffect(() => {
7 changes: 6 additions & 1 deletion pages/friends.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect } from 'react';
import { useSelector } from 'react-redux';

import { Session } from 'next-auth';
@@ -11,6 +11,7 @@ import { TopNavbarComponent } from 'src/components/atoms/TopNavbar';
import { TippingSuccess } from 'src/components/common/Tipping/render/Tipping.success';
import { DefaultLayout } from 'src/components/template/Default/DefaultLayout';
import { UserMetric } from 'src/interfaces/user';
import { updateSession } from 'src/lib/api/auth-link';
import { initialize } from 'src/lib/api/base';
import { healthcheck } from 'src/lib/api/healthcheck';
import i18n from 'src/locale';
@@ -40,6 +41,10 @@ const Friends: React.FC<FriendsPageProps> = props => {
const metric = useSelector<RootState, UserMetric | undefined>(
state => state.userState.user?.metric,
);
const { session } = props;
useEffect(() => {
if (!session?.user?.instanceURL) updateSession(session);
}, [session]);

return (
<DefaultLayout isOnProfilePage={false} {...props}>
9 changes: 7 additions & 2 deletions pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect } from 'react';

import { Session } from 'next-auth';
import { getSession } from 'next-auth/react';
@@ -15,6 +15,7 @@ import { AppStatusBanner } from 'src/components/common/Banner';
import { TippingSuccess } from 'src/components/common/Tipping/render/Tipping.success';
import { DefaultLayout } from 'src/components/template/Default/DefaultLayout';
import { generateAnonymousUser } from 'src/helpers/auth';
import { updateSession } from 'src/lib/api/auth-link';
import { initialize } from 'src/lib/api/base';
import * as ExperienceAPI from 'src/lib/api/experience';
import { healthcheck } from 'src/lib/api/healthcheck';
@@ -48,8 +49,12 @@ type HomePageProps = {
};

const Index: React.FC<HomePageProps> = props => {
const { title, description, image } = props;
const { session, title, description, image } = props;
const router = useRouter();
useEffect(() => {
if (!session?.user?.instanceURL) updateSession(session);
}, [session]);

return (
<>
<Head>
8 changes: 7 additions & 1 deletion pages/nft.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect } from 'react';

import { Session } from 'next-auth';
import { getSession } from 'next-auth/react';
@@ -11,6 +11,7 @@ import {
SectionTitle,
} from 'src/components/atoms/TopNavbar';
import { DefaultLayout } from 'src/components/template/Default/DefaultLayout';
import { updateSession } from 'src/lib/api/auth-link';
import { initialize } from 'src/lib/api/base';
import { healthcheck } from 'src/lib/api/healthcheck';
import i18n from 'src/locale';
@@ -35,6 +36,11 @@ type NFTPageProps = {
};

const NFTComponent: React.FC<NFTPageProps> = props => {
const { session } = props;
useEffect(() => {
if (!session?.user?.instanceURL) updateSession(session);
}, [session]);

return (
<DefaultLayout isOnProfilePage={false} {...props}>
<Head>
7 changes: 6 additions & 1 deletion pages/notification.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect } from 'react';
import { useSelector } from 'react-redux';

import { Session } from 'next-auth';
@@ -9,6 +9,7 @@ import Head from 'next/head';
import { NotificationsContainer } from 'src/components/Notifications';
import { TopNavbarComponent } from 'src/components/atoms/TopNavbar';
import { DefaultLayout } from 'src/components/template/Default/DefaultLayout';
import { updateSession } from 'src/lib/api/auth-link';
import { initialize } from 'src/lib/api/base';
import { healthcheck } from 'src/lib/api/healthcheck';
import i18n from 'src/locale';
@@ -38,6 +39,10 @@ const Notification: React.FC<NotificationPageProps> = props => {
const { total } = useSelector<RootState, NotificationState>(
state => state.notificationState,
);
const { session } = props;
useEffect(() => {
if (!session?.user?.instanceURL) updateSession(session);
}, [session]);

return (
<DefaultLayout isOnProfilePage={false} {...props}>
8 changes: 6 additions & 2 deletions pages/post/[postId].tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Sentry from '@sentry/nextjs';

import React from 'react';
import React, { useEffect } from 'react';
import { shallowEqual, useSelector } from 'react-redux';

import { Session } from 'next-auth';
@@ -22,6 +22,7 @@ import { generateAnonymousUser } from 'src/helpers/auth';
import { htmlToJson, isJson } from 'src/helpers/string';
import { Post } from 'src/interfaces/post';
import { User } from 'src/interfaces/user';
import { updateSession } from 'src/lib/api/auth-link';
import { initialize } from 'src/lib/api/base';
import { healthcheck } from 'src/lib/api/healthcheck';
import * as PostAPI from 'src/lib/api/post';
@@ -66,7 +67,10 @@ type PostPageParams = {
};

const PostPage: React.FC<PostPageProps> = props => {
const { removed, title, description, image } = props;
const { removed, title, description, image, session } = props;
useEffect(() => {
if (!session?.user?.instanceURL) updateSession(session);
}, [session]);

const router = useRouter();
const user = useSelector<RootState, User>(
8 changes: 6 additions & 2 deletions pages/profile/[id].tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Sentry from '@sentry/nextjs';

import React from 'react';
import React, { useEffect } from 'react';

import { Session } from 'next-auth';
import { getSession } from 'next-auth/react';
@@ -14,6 +14,7 @@ import { TopNavbarComponent } from 'components/atoms/TopNavbar';
import { TippingSuccess } from 'src/components/common/Tipping/render/Tipping.success';
import { DefaultLayout } from 'src/components/template/Default/DefaultLayout';
import { generateAnonymousUser } from 'src/helpers/auth';
import { updateSession } from 'src/lib/api/auth-link';
import { initialize } from 'src/lib/api/base';
import { healthcheck } from 'src/lib/api/healthcheck';
import * as UserAPI from 'src/lib/api/user';
@@ -50,7 +51,10 @@ type ProfilePageProps = {
const { publicRuntimeConfig } = getConfig();

const ProfilePageComponent: React.FC<ProfilePageProps> = props => {
const { title, description, image, isBanned } = props;
const { title, description, image, isBanned, session } = props;
useEffect(() => {
if (!session?.user?.instanceURL) updateSession(session);
}, [session]);

const router = useRouter();

8 changes: 7 additions & 1 deletion pages/search.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect } from 'react';
import { useSelector } from 'react-redux';

import { Session } from 'next-auth';
@@ -9,6 +9,7 @@ import Head from 'next/head';
import { SearchResultContainer } from 'src/components/Search/SearchResultContainer';
import { TippingSuccess } from 'src/components/common/Tipping/render/Tipping.success';
import { DefaultLayout } from 'src/components/template/Default/DefaultLayout';
import { updateSession } from 'src/lib/api/auth-link';
import { initialize } from 'src/lib/api/base';
import { healthcheck } from 'src/lib/api/healthcheck';
import i18n from 'src/locale';
@@ -43,6 +44,11 @@ const Search: React.FC<SearchProps> = props => {
state => state.userState,
);

const { session } = props;
useEffect(() => {
if (!session?.user?.instanceURL) updateSession(session);
}, [session]);

if (!user && !anonymous) return null;

return (
7 changes: 6 additions & 1 deletion pages/settings.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect } from 'react';

import { Session } from 'next-auth';
import { getSession } from 'next-auth/react';
@@ -13,6 +13,7 @@ import {
} from 'src/components/Settings';
import { TopNavbarComponent } from 'src/components/atoms/TopNavbar';
import { DefaultLayout } from 'src/components/template/Default/DefaultLayout';
import { updateSession } from 'src/lib/api/auth-link';
import { initialize } from 'src/lib/api/base';
import { healthcheck } from 'src/lib/api/healthcheck';
import i18n from 'src/locale';
@@ -38,6 +39,10 @@ type SettingPageProps = {

const Settings: React.FC<SettingPageProps> = props => {
const { query } = useRouter();
const { session } = props;
useEffect(() => {
if (!session?.user?.instanceURL) updateSession(session);
}, [session]);

const settings = useSettingList();

Loading

0 comments on commit 1e5a358

Please sign in to comment.