refactoring: simplifying file names
This commit is contained in:
11
README.md
11
README.md
@@ -12,11 +12,6 @@
|
|||||||
# Authentication
|
# Authentication
|
||||||
Authentication consists of the following parts:
|
Authentication consists of the following parts:
|
||||||
* `next-auth` boilerplate
|
* `next-auth` boilerplate
|
||||||
* `middleware.ts` = hooks-up `next-auth` into the page processing pipeline
|
* `middleware.ts` = hooks-up `next-auth` into the page processing pipeline - user session is checked before any page is rendered
|
||||||
* `auth.config.ts` = defines how user session is to be checked and redirects anonymous user to login page
|
* `auth.ts` = defines how the authentication is done, and how session is checked (used by middleware)
|
||||||
* `auth.ts` = verifies user credentials during the log-in action (i.e. against a database)
|
* `/app/api/[...nextauth]/route.ts` = defines route which shows an authentication form
|
||||||
* exports `auth`, `signIn`, `signOut` actions
|
|
||||||
* UI boilerplate
|
|
||||||
* `sidenav.tsx` = implements logout action - calls `signOut` from `auth.ts`
|
|
||||||
* `login-form.tsx` = implements login form
|
|
||||||
* `actions.ts` = handles login-form validation and submition - calls `signIn` from `auth.ts`
|
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
export { GET, POST } from '@/app/lib/auth.google';
|
export { GET, POST } from '@/app/lib/auth';
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
import NextAuth, { NextAuthConfig } from 'next-auth';
|
|
||||||
import GoogleProvider from 'next-auth/providers/google';
|
|
||||||
|
|
||||||
export const authConfig:NextAuthConfig = {
|
|
||||||
callbacks: {
|
|
||||||
async signIn({ account, profile }) {
|
|
||||||
if (account?.provider === "google") {
|
|
||||||
return profile?.email_verified === true && profile?.email?.endsWith("@google.com") === true
|
|
||||||
}
|
|
||||||
return true // Do different verification for other providers that don't have `email_verified`
|
|
||||||
},
|
|
||||||
authorized({ auth, request: { nextUrl } }) {
|
|
||||||
const isLoggedIn = !!auth?.user;
|
|
||||||
return(isLoggedIn);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
providers: [
|
|
||||||
GoogleProvider({
|
|
||||||
clientId: process.env.GOOGLE_ID,
|
|
||||||
clientSecret: process.env.GOOGLE_SECRET,
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
session: {
|
|
||||||
// Use JSON Web Tokens for session instead of database sessions.
|
|
||||||
// This option can be used with or without a database for users/accounts.
|
|
||||||
// Note: `jwt` is automatically set to `true` if no database is specified.
|
|
||||||
strategy: 'jwt'
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@@ -5,7 +5,7 @@ import { AddLocationButton } from './ui/AddLocationButton';
|
|||||||
import clientPromise from './lib/mongodb';
|
import clientPromise from './lib/mongodb';
|
||||||
import { BillingLocation } from './lib/db-types';
|
import { BillingLocation } from './lib/db-types';
|
||||||
import { PageFooter } from './ui/PageFooter';
|
import { PageFooter } from './ui/PageFooter';
|
||||||
import { auth } from '@/app/lib/auth.google';
|
import { auth } from '@/app/lib/auth';
|
||||||
import { redirect } from 'next/navigation';
|
import { redirect } from 'next/navigation';
|
||||||
|
|
||||||
const getNextYearMonth = (yearMonth:number) => {
|
const getNextYearMonth = (yearMonth:number) => {
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
* @description hooks-up `next-auth` into the page processing pipeline
|
* @description hooks-up `next-auth` into the page processing pipeline
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { auth } from '@/app/lib/auth.google'
|
import { auth } from '@/app/lib/auth'
|
||||||
|
|
||||||
export default auth; // middleware will call NextAuth's `auth` method, which will in turn call) see `auth.config.google.ts`
|
export default auth; // middleware will call NextAuth's `auth` method, which will in turn call) see `auth.ts`
|
||||||
|
|
||||||
export const config = {
|
export const config = {
|
||||||
// midleware will NOT be called for paths: ['/api/auth/*', '/_next/static/*', '/_next/image*']
|
// midleware will NOT be called for paths: ['/api/auth/*', '/_next/static/*', '/_next/image*']
|
||||||
|
|||||||
Reference in New Issue
Block a user