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
aafd0c7b
Commit
aafd0c7b
authored
1 year ago
by
Caner
Browse files
Options
Downloads
Patches
Plain Diff
funktioniert noch nicht
parent
30292c28
No related branches found
Branches containing commit
No related tags found
1 merge request
!45
Email verify
Pipeline
#38985
failed
1 year ago
Stage: build
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/api/email/route.ts
+12
-16
12 additions, 16 deletions
app/api/email/route.ts
components/user-auth-form.tsx
+30
-26
30 additions, 26 deletions
components/user-auth-form.tsx
with
42 additions
and
42 deletions
app/api/email/route.ts
+
12
−
16
View file @
aafd0c7b
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'
next
'
;
import
*
as
nodemailer
from
'
nodemailer
'
;
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/
const
transporter
=
nodemailer
.
createTransport
({
service
:
"
gmail
"
,
...
...
@@ -26,26 +29,19 @@ export default async function handler(
// https://nodemailer.com/message/#common-fields
const
mailData
=
{
from
:
email
,
from
:
process
.
env
.
NODEMAIL_MAIL
,
to
:
email
,
subject
:
`
${
subject
}
`
,
text
:
`
${
subject
}
| Sent from:
${
email
}
`
,
text
:
`
${
subject
}
| Sent from:
${
process
.
env
.
NODEMAIL_MAIL
}
`
,
html
:
`
${
html
}
`
,
};
await
new
Promise
((
resolve
,
reject
)
=>
{
transporter
.
sendMail
(
mailData
,
(
err
:
Error
|
null
,
info
)
=>
{
if
(
err
)
{
reject
(
err
);
return
res
.
status
(
500
)
.
json
({
error
:
err
.
message
||
'
Something went wrong
'
});
}
else
{
resolve
(
info
.
accepted
);
res
.
status
(
200
).
json
({
message
:
'
Message sent!
'
});
}
});
});
try
{
const
info
=
await
transporter
.
sendMail
(
mailData
);
res
.
status
(
200
).
json
({
message
:
'
Message sent!
'
,
info
});
}
catch
(
err
)
{
res
.
status
(
500
).
json
({
error
:
err
||
'
Something went wrong Message could not be send
'
});
}
return
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
components/user-auth-form.tsx
+
30
−
26
View file @
aafd0c7b
...
...
@@ -36,6 +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
'
,
text
:
'
Please verify your email address.
'
,
}),
});
const
body
=
await
res
.
json
();
if
(
res
.
ok
)
{
alert
(
`
${
body
.
message
}
🚀`
);
}
if
(
res
.
status
===
400
)
{
alert
(
`
${
body
.
message
}
😢`
);
}
}
catch
(
err
)
{
console
.
log
(
'
Something went wrong:
'
,
err
);
}
}
async
function
onSubmit
(
data
:
FormData
)
{
setIsLoading
(
true
)
...
...
@@ -95,32 +124,7 @@ export function UserAuthForm({ type, className, ...props }: UserAuthFormProps) {
action
:
<
ToastAction
altText
=
"Try again"
>
Try again
</
ToastAction
>,
})
}
try
{
const
res
=
await
fetch
(
'
/api/email
'
,
{
method
:
'
POST
'
,
headers
:
{
'
Content-Type
'
:
'
application/json
'
,
},
body
:
JSON
.
stringify
(
subject
:
"
Test
"
,
email
:
data
.
email
,
),
});
const
body
=
await
res
.
json
();
if
(
res
.
ok
)
{
alert
(
`
${
body
.
message
}
🚀`
);
}
if
(
res
.
status
===
400
)
{
alert
(
`
${
body
.
message
}
😢`
);
}
}
catch
(
err
)
{
console
.
log
(
'
Something went wrong:
'
,
err
);
}
await
sendVerificationEmail
(
data
.
email
!
)
router
.
push
(
"
/home
"
)
...
...
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