-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(auth): replace custom auth with next-auth
- Loading branch information
Showing
29 changed files
with
859 additions
and
579 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { LoggedInUser } from 'models/User'; | ||
import { GetServerSidePropsContext } from 'next'; | ||
import { signIn, signOut, getSession } from 'next-auth/client'; | ||
|
||
export interface FeideProfile { | ||
sub: string; | ||
'connect-userid_sec': string[]; | ||
'dataporten-userid_sec': string[]; | ||
name: string; | ||
email: string; | ||
email_verified: boolean; | ||
picture: string; | ||
} | ||
|
||
export const OIDC_CLIENT_NAME = 'feide'; | ||
|
||
export const logIn = async () => { | ||
await signIn(OIDC_CLIENT_NAME); | ||
}; | ||
|
||
export const logOut = async () => { | ||
await signOut(); | ||
}; | ||
|
||
export const getUserClient = async () => { | ||
const session = await getSession(); | ||
const user = (session as any) as LoggedInUser | null; | ||
return user; | ||
}; | ||
|
||
export const getUserServer = async (ctx: GetServerSidePropsContext) => { | ||
const session = await getSession(ctx); | ||
const user = (session as any) as LoggedInUser | null; | ||
return user; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,8 @@ | ||
import { LoggedInUser } from 'models/User'; | ||
import useSWR from 'swr'; | ||
|
||
import { fetcher } from '../fetcher'; | ||
import { useSession } from 'next-auth/client'; | ||
|
||
export const useUser = () => { | ||
const { data, mutate, revalidate } = useSWR<{ user: LoggedInUser }>('/api/auth/user', fetcher); | ||
const loading = !data; | ||
const user = data?.user; | ||
const functions = { mutate, loading, revalidate }; | ||
return [user, functions] as [typeof user, typeof functions]; | ||
const [session, loading] = useSession(); | ||
const user = (session as any) as LoggedInUser | null; | ||
return [user, loading] as [typeof user, typeof loading]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.