Skip to content

Commit

Permalink
Add Password for Demo User
Browse files Browse the repository at this point in the history
  • Loading branch information
aftabrehan committed Jan 19, 2024
1 parent 46711fb commit 1f0ee98
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import type { Metadata } from 'next'
import { Inter } from 'next/font/google'
import './globals.css'

import Header from '@/components/Header'
import { ThemeProvider } from '@/components/ThemeProvider'
import ClientProviders from '@/components/ClientProviders'
import FirebaseAuthProvider from '@/components/FirebaseAuthProvider'
import SubscriptionProvider from '@/components/SubscriptionProvider'
import { Toaster } from '@/components/ui/toaster'

import './globals.css'

export const metadata: Metadata = {
title: 'Chatwex',
description: 'Chat with anyone in your language.',
Expand Down
5 changes: 3 additions & 2 deletions auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const authOptions: NextAuthOptions = {
username: { label: 'Username', type: 'text', placeholder: 'johndoe' },
password: { label: 'Password', type: 'password' },
},
async authorize() {
async authorize(credentials) {
const user = {
id: 'demo_user_id',
name: 'John Doe',
Expand All @@ -27,7 +27,8 @@ export const authOptions: NextAuthOptions = {
'https://images.unsplash.com/photo-1535713875002-d1d0cf377fde?w=72&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8M3x8dXNlciUyMHByb2ZpbGV8ZW58MHx8MHx8fDA%3D',
}

if (user) return user
if (credentials?.password === process.env.DEMO_USER_PASSWORD)
return user
else return null
},
}),
Expand Down
2 changes: 1 addition & 1 deletion components/UserButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function UserButton({ session }: { session: Session | null }) {
if (!session) {
const handleLogin = async (type: 'credentials' | 'google') => {
setIsLoading({ ...isLoading, [type]: true })
await signIn(type)
await signIn(type, { password: process.env.DEMO_USER_PASSWORD })
setIsLoading({ ...isLoading, [type]: false })
}

Expand Down
1 change: 1 addition & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const nextConfig = {
domains: ['github.com', 'lh3.googleusercontent.com', 'images.unsplash.com'],
},
env: {
DEMO_USER_PASSWORD: process.env.DEMO_USER_PASSWORD,
FIREBASE_API_KEY: process.env.FIREBASE_API_KEY,
FIREBASE_AUTH_DOMAIN: process.env.FIREBASE_AUTH_DOMAIN,
FIREBASE_PROJECT_ID: process.env.FIREBASE_PROJECT_ID,
Expand Down

0 comments on commit 1f0ee98

Please sign in to comment.