New Applicationbutton in the dashboard to be redirected to the Application creation form.
YOUR APPLICATION NAME
YOUR APPLICATION WEBSITE
YOUR APPLICATION DESCRIPTION
Next Stepbutton.
Settingsbutton to configure the connection for the selected environment. Note that you can have one provider configured per environment, and you can change the environment name from the top navigation bar.
Skip Step. You’ll be invited to configure the application redirections; this step is required to know where your users should be redirected after a successful (or not) authentication. The next step will be to integrate Authdog SDK in the Next.js application.
1
npm install @authdog/react @authdog/browser @authdog/shared
1
yarn add @authdog/react @authdog/browser @authdog/shared
1
pnpm add @authdog/react @authdog/browser @authdog/shared
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// pages/_app.tsx
import type { AppProps } from "next/app";
import { AuthdogProvider } from "@authdog/react";
export default function App({ Component, pageProps }: AppProps) {
const authnUri =
"<copied from application configure dashboard in settings/endpoints>";
const webLoginUri =
"<copied from application configure dashboard in settings/endpoints>";
return (
<AuthdogProvider
authnApi={authnUri}
webLoginUri={webLoginUri}
{...pageProps}
>
<Component {...pageProps} />
</AuthdogProvider>
);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { useEffect } from "react";
import { persistTokenFromUri } from "@authdog/browser";
import { useSignin } from "@authdog/react";
import { DashboardButton } from "../components/DashboardButton";
export default function Home() {
useEffect(() => {
// this is used to persist the token from the uri to the local storage when you’re not using cookie based authentication
persistTokenFromUri();
}, []);
const { webLoginUri } = useSignin();
return (
<div>
// You navbar code or wherever you want to add a Signin button
<button onClick={() => window.location.assign(webLoginUri)}>
Access Dashboard
</button>
</div>
);
})
Routingtab.
http://localhost:3000/dashboardas a success redirection URI. You also need to set the error redirection, for instance
http://localhost:3000/error.
useIdentityhook from
@authdog/react:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { useEffect, useState } from "react";
import { useIdentity } from "@authdog/react";
export default function Dashboard() {
const { user } = useIdentity();
return (
{user && (
<div style={{ display: "flex", alignItems: "center" }}>
Welcome {user.displayName}
<img
src={user?.photos?.length > 0 ? user.photos[0].value : ""}
width="50"
height="50"
style={{ borderRadius: "10px" }}
/>
</div>
)}
);
}
@authdog/browser:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { logout } from "@authdog/browser";
export const SignoutButton = () => {
return (
<a
style={{
cursor: "pointer",
}}
onClick={() => {
logout();
}}
>
<span className="relative">Sign Out</span>
</a>
);
};
SignedInhelper.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { SignoutButton } from "../components/SignoutButton";
import { SignedIn } from "@authdog/react";
export const Navbar = () => (
<SignedIn>
{user && (
<div className="text-2xl">
<div style={{ display: "flex", alignItems: "center" }}>
Welcome {user.displayName}
<img
src={user?.photos?.length > 0 ? user.photos[0].value : ""}
width="50"
height="50"
style={{ borderRadius: "10px" }}
/>
</div>
</div>
)}
<SignoutButton />
</SignedIn>
);
Prev
Access tokens
Next
Login Form Setup