Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
project_ss23_gameunity
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Yusuf Akgül
project_ss23_gameunity
Commits
9536c40d
Commit
9536c40d
authored
1 year ago
by
Caner
Browse files
Options
Downloads
Patches
Plain Diff
little fix
parent
aafd0c7b
No related branches found
Branches containing commit
No related tags found
1 merge request
!45
Email verify
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/api/email/route.ts
+2
-2
2 additions, 2 deletions
app/api/email/route.ts
components/user-auth-form.tsx
+26
-26
26 additions, 26 deletions
components/user-auth-form.tsx
lib/config/nodemailer.ts
+0
-62
0 additions, 62 deletions
lib/config/nodemailer.ts
with
28 additions
and
90 deletions
app/api/email/route.ts
+
2
−
2
View file @
9536c40d
...
...
@@ -11,12 +11,12 @@ export default async function handler(
}
// https://nodemailer.com/smtp/
const
transporter
=
nodemailer
.
createTransport
({
service
:
"
gmail
"
,
host
:
"
smtp.gameunity.tgos@gmail.com
"
,
port
:
587
,
auth
:
{
user
:
process
.
env
.
NODEMAIL_MAIL
,
pass
:
process
.
env
.
NODEMAIL_PW
,
},
secure
:
false
,
// Default value but showing for explicitness
});
const
{
subject
,
email
,
html
}
=
req
.
body
;
...
...
This diff is collapsed.
Click to expand it.
components/user-auth-form.tsx
+
26
−
26
View file @
9536c40d
...
...
@@ -36,34 +36,34 @@ export function UserAuthForm({ type, className, ...props }: UserAuthFormProps) {
const
router
=
useRouter
();
const
searchParams
=
useSearchParams
()
async
function
sendVerificationEmail
(
email
:
string
)
{
try
{
const
res
=
await
fetch
(
'
/api/email
'
,
{
method
:
'
POST
'
,
headers
:
{
'
Content-Type
'
:
'
application/json
'
,
},
body
:
JSON
.
stringify
({
email
,
subject
:
'
Email Verification
'
,
text
:
'
Please verify your email address.
'
,
}),
});
//
async function sendVerificationEmail(email: string) {
//
try {
//
const res = await fetch('/api/email', {
//
method: 'POST',
//
headers: {
//
'Content-Type': 'application/json',
//
},
//
body: JSON.stringify({
//
email,
//
subject: 'Email Verification',
//
html: '<h1>
Please verify your email address.
</h1>
',
//
}),
//
});
const
body
=
await
res
.
json
();
//
const body = await res.json();
if
(
res
.
ok
)
{
alert
(
`
${
body
.
message
}
🚀`
);
}
//
if (res.ok) {
//
alert(`${body.message} 🚀`);
//
}
if
(
res
.
status
===
400
)
{
alert
(
`
${
body
.
message
}
😢`
);
}
}
catch
(
err
)
{
console
.
log
(
'
Something went wrong:
'
,
err
);
}
//
if (res.status === 400) {
//
alert(`${body.message} 😢`);
//
}
//
} catch (err) {
//
console.log('Something went wrong: ', err);
//
}
}
//
}
async
function
onSubmit
(
data
:
FormData
)
{
setIsLoading
(
true
)
...
...
@@ -89,10 +89,11 @@ export function UserAuthForm({ type, className, ...props }: UserAuthFormProps) {
setIsLoading
(
false
)
return
toast
({
variant
:
"
destructive
"
,
title
:
"
Uh oh! Something went wrong.
"
,
title
:
"
THIS
Uh oh! Something went wrong.
"
,
description
:
"
Your sign up request failed. Please try again.
"
,
})
}
// await sendVerificationEmail(data.email!)
}
const
signInResult
=
await
signIn
(
"
credentials
"
,
{
...
...
@@ -124,7 +125,6 @@ export function UserAuthForm({ type, className, ...props }: UserAuthFormProps) {
action
:
<
ToastAction
altText
=
"Try again"
>
Try again
</
ToastAction
>,
})
}
await
sendVerificationEmail
(
data
.
email
!
)
router
.
push
(
"
/home
"
)
...
...
This diff is collapsed.
Click to expand it.
lib/config/nodemailer.ts
deleted
100644 → 0
+
0
−
62
View file @
aafd0c7b
import
*
as
nodemailer
from
"
nodemailer
"
;
import
{
MailOptions
}
from
"
nodemailer/lib/json-transport
"
;
export
class
Emailer
{
private
readonly
transporter
:
nodemailer
.
Transporter
;
constructor
()
{
this
.
transporter
=
nodemailer
.
createTransport
({
service
:
"
gmail
"
,
auth
:
{
user
:
process
.
env
.
NODEMAIL_MAIL
,
pass
:
process
.
env
.
NODEMAIL_PW
,
},
});
}
public
sendEmail
(
mailOptions
:
MailOptions
)
{
return
this
.
transporter
.
sendMail
(
mailOptions
);
}
public
notifyAdminForNewUser
(
email
:
string
,
username
:
string
)
{
this
.
sendEmail
(
notifyAdminNewUserEmailTemplate
(
email
,
username
));
}
public
notifyUserForSignup
(
email
:
string
,
username
:
string
)
{
this
.
sendEmail
(
newUserEmailTemplate
(
email
,
username
));
}
}
export
const
emailer
=
new
Emailer
();
export
const
newUserEmailTemplate
=
(
email
:
string
,
username
:
string
)
=>
{
return
{
from
:
process
.
env
.
GMAIL_USER
,
to
:
email
,
subject
:
`
${
username
}
, Welcome to the our website`
,
text
:
"
Welcome to the our website
"
,
html
:
`
<h1>Welcome to our website!</h1>
<p>We're glad you've decided to join us. We hope you find everything you're looking for here and enjoy using our site.</p>
<p>If you have any questions or need any help, please don't hesitate to contact us. Thank you for signing up!</p>
`
,
}
as
MailOptions
;
};
export
const
notifyAdminNewUserEmailTemplate
=
(
email
:
string
,
username
:
string
)
=>
{
return
{
from
:
process
.
env
.
GMAIL_USER
,
to
:
process
.
env
.
GMAIL_USER
,
subject
:
`New User:
${
username
}
- email:
${
email
}
`
,
text
:
`New User:
${
username
}
- email:
${
email
}
`
,
html
:
`
<h1>New User:
${
username
}
</h1>
<p>email:
${
email
}
</p>
`
,
}
as
MailOptions
;
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment