Skip to content

Add signout feature #3

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 2 commits into
base: add-next-auth-files
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
10 changes: 5 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ NEXTAUTH_URL="http://localhost:3000"
JWT_SECRET="some-hedgehogs-are-not-so-cuddly-ow"
# The Client ID for the App Registration created within your Azure B2C Tenant
#### UPDATE WITH YOUR OWN VALUE ####
AUTH_CLIENT_ID="azureb2c-app-registration-client-id"
AUTH_CLIENT_ID="your-azureb2c-app-registration-client-id"
# The Client Secret for the App Registration created within your Azure B2C Tenant
#### UPDATE WITH YOUR OWN VALUE ####
AUTH_CLIENT_SECRET="azureb2c-app-registration-client-secret"
# Your Azure B2C Tenant name, like someTenantName.onmicrosoft.com
AUTH_CLIENT_SECRET="your-azureb2c-app-registration-client-secret"
# Your Azure B2C Tenant name, like yourAzureB2CTenantName.onmicrosoft.com
#### UPDATE WITH YOUR OWN VALUE ####
AUTH_TENANT_NAME="someTenantName"
AUTH_TENANT_NAME="yourAzureB2CTenantName"
# Your Azure B2C Sign in (and/or sign up) user flow name.
# This will start with B2C_1_
#### UPDATE WITH YOUR OWN VALUE ####
USER_FLOW="signupsignin1"
USER_FLOW="B2C_1_signupsignin1"
16 changes: 16 additions & 0 deletions pages/auth/signout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { signOut } from 'next-auth/client'

export default function Signout() {
if (typeof window !== 'undefined') {
console.log('Is client - signing out')
console.log('*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***')

signOut({ callbackUrl: process.env.NEXTAUTH_URL })
}
else {
console.log('Not client - not signing out')
console.log('*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***')
}

return null
}
12 changes: 11 additions & 1 deletion pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,17 @@ export default function Home() {
</p>
</a>
</div>
<div>You are signed in! You can also sign out if you like.</div>
<div>
<p>You are signed in! You can also sign out if you like.</p>
<ul>
<li>
<a style={{color: 'blue'}} href="/api/auth/signout/azureb2c">Sign Out (API)</a>
</li>
<li>
<a style={{color: 'blue'}} href={`https://${process.env.AUTH_TENANT_NAME}.b2clogin.com/${process.env.AUTH_TENANT_NAME}.onmicrosoft.com/${process.env.USER_FLOW}/oauth2/v2.0/logout?post_logout_redirect_uri=${process.env.NEXTAUTH_URL}/auth/signout`}>Sign Out (FULL)</a>
</li>
</ul>
</div>
</>
: <div>
You are not signed in! <a style={{color: 'blue'}} href="/api/auth/signin">You must sign in to access documentation!</a>
Expand Down