Skip to content

Remove server side okta code from client #448

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

Open
wants to merge 1 commit into
base: staging
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import './globals.css';
import { auth } from '@/auth';
import { SessionProvider } from 'next-auth/react';
import { SessionProvider } from '@/auth/client';

import LayoutWrapper from '@/components/layout-wrapper';
import { getComponentsService } from '@/lib/contentStack/contentStackService';
Expand Down
5 changes: 3 additions & 2 deletions src/app/private/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { BasicEmptyState } from '@leafygreen-ui/empty-state';
import ArrowLeftIcon from '@leafygreen-ui/icon/dist/ArrowLeft';
// @ts-expect-error
import LogInIcon from '@leafygreen-ui/icon/dist/LogIn';
import { login } from '@/auth';
import { signIn } from '@/auth/client';

import { ComingSoon, Security } from '@/components/glyphs';
import { useSession } from '@/hooks';

Expand All @@ -33,7 +34,7 @@ export default function Private() {
primaryButton={
<Button
variant="primary"
onClick={() => login()}
onClick={() => signIn('okta')}
leftGlyph={<LogInIcon />}
>
Log In
Expand Down
3 changes: 3 additions & 0 deletions src/auth/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { signOut, signIn, SessionProvider, useSession } from 'next-auth/react';

export { signOut, signIn, SessionProvider, useSession };
5 changes: 3 additions & 2 deletions src/components/global/LogIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

import { css } from '@emotion/css';
import Button from '@leafygreen-ui/button';
import { login } from '@/auth/login';
import { signIn } from '@/auth/client';

export function LogIn() {
return (
<Button
size="small"
onClick={() => login()}
// client-side log in
onClick={() => signIn('okta')}
className={css`
border-radius: 50px;
`}
Expand Down
4 changes: 2 additions & 2 deletions src/components/global/PrivateContentWall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { BasicEmptyState } from '@leafygreen-ui/empty-state';
// @ts-expect-error
import LogInIcon from '@leafygreen-ui/icon/dist/LogIn';

import { login } from '@/auth';
import { signIn } from '@/auth/client';

import { Security } from '@/components/glyphs';

Expand All @@ -19,7 +19,7 @@ export function PrivateContentWall() {
primaryButton={
<Button
variant="primary"
onClick={() => login()}
onClick={() => signIn('okta')}
leftGlyph={<LogInIcon />}
>
Log In
Expand Down
4 changes: 1 addition & 3 deletions src/components/global/UserMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import { Menu, MenuItem } from '@leafygreen-ui/menu';
import { Body, Description } from '@leafygreen-ui/typography';

import { LogIn } from './LogIn';
import { logout } from '@/auth';

import { signOut } from 'next-auth/react';
import { signOut } from '@/auth/client';
import { useSession } from '@/hooks';

export function UserMenu() {
Expand Down Expand Up @@ -44,7 +43,6 @@ export function UserMenu() {
<MenuItem
glyph={<LogOutIcon />}
onClick={async () => {
logout();
// https://github.com/nextauthjs/next-auth/discussions/11271#discussioncomment-12272576
// Session does not clear reliably without forcing a hard refresh
// client-side signOut; use signOut from next-auth/react whenever signing out
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { useMemo } from 'react';
import { Session } from '@/auth';
import { useSession as useAuthSession } from 'next-auth/react';
import { useSession as useAuthSession } from '@/auth/client';

export type LGSession = Partial<Session> & { isLoggedIn?: boolean };

Expand Down
Loading