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
f9d6aacb
Commit
f9d6aacb
authored
1 year ago
by
Caner
Browse files
Options
Downloads
Patches
Plain Diff
MAN KANN EINE EMAIL SENDEN
parent
9536c40d
No related branches found
Branches containing commit
No related tags found
1 merge request
!45
Email verify
Pipeline
#39111
passed
1 year ago
Stage: build
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/api/email/route.ts
+20
-30
20 additions, 30 deletions
app/api/email/route.ts
components/user-auth-form.tsx
+26
-25
26 additions, 25 deletions
components/user-auth-form.tsx
lib/auth.ts
+0
-4
0 additions, 4 deletions
lib/auth.ts
with
46 additions
and
59 deletions
app/api/email/route.ts
+
20
−
30
View file @
f9d6aacb
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'
next
'
;
import
nodemailer
from
'
nodemailer
'
;
// Nodemailer docs: // https://nodemailer.com/about/
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
)
{
if
(
req
.
method
!==
"
POST
"
)
{
return
res
.
status
(
405
).
json
({
error
:
"
Method Not Allowed
"
});
}
// https://nodemailer.com/smtp/
import
nodemailer
from
"
nodemailer
"
;
import
{
NextResponse
}
from
"
next/server
"
;
export
async
function
POST
(
req
:
Request
)
{
const
{
email
,
subject
,
html
}
=
await
req
.
json
();
const
transporter
=
nodemailer
.
createTransport
({
host
:
"
smtp.gameunity.tgos@gmail.com
"
,
port
:
587
,
service
:
'
gmail
'
,
host
:
'
smtp.gmail.com
'
,
auth
:
{
user
:
process
.
env
.
NODEMAIL_MAIL
,
pass
:
process
.
env
.
NODEMAIL_PW
,
},
});
const
{
subject
,
email
,
html
}
=
req
.
body
;
if
(
!
subject
||
!
email
||
!
html
)
{
return
res
.
status
(
400
)
.
json
({
message
:
'
Please fill out the necessary fields
'
});
}
// https://nodemailer.com/message/#common-fields
const
mailData
=
{
from
:
process
.
env
.
NODEMAIL_MAIL
,
from
:
email
,
to
:
email
,
subject
:
`
${
subject
}
`
,
text
:
`
${
subject
}
| Sent from:
${
process
.
env
.
NODEMAIL_MAIL
}
`
,
text
:
`
${
subject
}
| Sent from:
${
email
}
`
,
html
:
`
${
html
}
`
,
};
let
emailRes
;
try
{
const
info
=
await
transporter
.
sendMail
(
mailData
);
res
.
status
(
200
).
json
({
message
:
'
Message sent!
'
,
info
});
emailRes
=
await
transporter
.
sendMail
(
mailData
);
console
.
log
(
"
Message sent
"
,
emailRes
.
messageId
);
}
catch
(
err
)
{
res
.
status
(
500
).
json
({
error
:
err
||
'
Something went wrong Message could not be send
'
});
console
.
log
(
err
);
console
.
error
(
"
Error email could not be send
"
);
}
return
;
console
.
log
(
emailRes
?.
messageId
)
return
NextResponse
.
json
({
success
:
true
,
messageId
:
emailRes
?.
messageId
})
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
components/user-auth-form.tsx
+
26
−
25
View file @
f9d6aacb
...
...
@@ -36,34 +36,35 @@ 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',
// html: '<h1>Please verify your email address.</h1>',
// }),
// });
//muss noch exportiert werden
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
:
'
Please verify your email address.
'
,
}),
});
//
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
)
...
...
@@ -93,7 +94,6 @@ export function UserAuthForm({ type, className, ...props }: UserAuthFormProps) {
description
:
"
Your sign up request failed. Please try again.
"
,
})
}
// await sendVerificationEmail(data.email!)
}
const
signInResult
=
await
signIn
(
"
credentials
"
,
{
...
...
@@ -129,6 +129,7 @@ export function UserAuthForm({ type, className, ...props }: UserAuthFormProps) {
router
.
push
(
"
/home
"
)
if
(
type
===
"
signup
"
)
{
await
sendVerificationEmail
(
data
.
email
!
)
return
toast
({
title
:
"
Congratulations!
"
,
description
:
"
Your account has been created. You will be redirected shortly.
"
,
...
...
This diff is collapsed.
Click to expand it.
lib/auth.ts
+
0
−
4
View file @
f9d6aacb
...
...
@@ -55,10 +55,6 @@ export const authOptions: NextAuthOptions = {
throw
new
Error
(
'
invalid password
'
)
}
if
(
!
user
.
emailVerified
){
throw
new
Error
(
'
email not verifyed
'
)
}
return
{
id
:
user
.
id
,
username
:
user
.
username
,
...
...
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