Skip to content

Commit

Permalink
email verify fix
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorOlikov committed Apr 5, 2024
1 parent 9bd9139 commit b3f8cf1
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 11 deletions.
3 changes: 1 addition & 2 deletions app/Notifications/VerifyEmailCustom.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ protected function verificationUrl($notifiable): string
->getTimestamp(),

];
//ksort($params);

// then create API url for verification. my API have `/api` prefix,
// so i don't want to show that url to users
Expand All @@ -99,7 +98,7 @@ protected function verificationUrl($notifiable): string
$signature = hash_hmac('sha256', $url, $key);


$frontendUrl = \config('app.frontend_url') . '/verify-email/';
$frontendUrl = \config('app.frontend_url') . '/verify-email-request/';

// generate url for your SPA page ,send to user email ! Link for FRONTEND !

Expand Down
1 change: 1 addition & 0 deletions resources/js/src/pages/SendEmailVerificationPage.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<template>
<h1>Отправить письмо с ссылкой на почту для подтверждения почты!</h1>
<h1>Кнопка отправить еще!!</h1>
</template>

<script setup>
Expand Down
41 changes: 37 additions & 4 deletions resources/js/src/pages/VerifyEmailRequestPage.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
<script setup>
</script>

<template>
<h1>Взять хэш из GET PARAMS и отправить GET запрос с HASH на VERIFY HASH</h1>
</template>


<script setup>
import {useRoute} from "vue-router";
import {useAuthStore} from "@/store/AuthStore.js";
import router from "@/router/router.js";
import axiosJwtApi from "@/Axios/Api.js";
import {onMounted} from "vue";
const route = useRoute();
const authStore = useAuthStore();
const url = `${authStore.appDomain}${authStore.apiVersion}/auth/email/verify/${route.params.id}/${route.params.hash}?expires=${route.query.expires}&signature=${route.query.signature}`;
const verifyEmailRequest = async () => {
if (!authStore.auth) {
await router.push('/login')
} else if (authStore.userInfo.value.email_verified) {
await router.push('/')
}
try {
const response = await axiosJwtApi.get(url)
authStore.userInfo.value.email_verified = true
localStorage.setItem('userInfo', JSON.stringify(authStore.userInfo))
await router.push('/')
} catch (err) {
console.log(err)
}
}
onMounted(() => {
verifyEmailRequest()
})
</script>

<style scoped>
</style>
2 changes: 1 addition & 1 deletion resources/js/src/router/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const routes = [
meta: { authRequired: true, emailVerifyRequired: false }
},
{
path: '/verify-email-request',
path: '/verify-email-request/:id/:hash',
component: VerifyEmailRequestPage,
name: 'verifyEmailRequest',
meta: { authRequired: true, emailVerifyRequired: false }
Expand Down
12 changes: 9 additions & 3 deletions resources/js/src/store/AuthStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,11 @@ export const useAuthStore

const checkUserAuthStatus = async () => {
const accessToken = localStorage.getItem('token')
if (accessToken) {
userInfo.value = JSON.parse(localStorage.getItem('userInfo'))
const userInfoStorage = localStorage.getItem('userInfo')


if (accessToken && userInfoStorage) {
userInfo.value = JSON.parse(userInfoStorage)
auth.value = true
} else {
auth.value = false
Expand All @@ -111,5 +114,8 @@ export const useAuthStore
errorMessage,
isErrorMessage,
userInfo,
expiresIn}
expiresIn,
appDomain,
apiVersion
}
});
2 changes: 1 addition & 1 deletion routes/v1/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use App\Http\Controllers\ResetPasswordController;


Route::prefix('/auth')->middleware('api')->group(function () {
Route::prefix('/auth')->middleware('auth:api')->group(function () {

Route::post('/register',[AuthController::class,'register'])->name('register');
Route::post('/login',[AuthController::class,'login'])->name('login');
Expand Down

0 comments on commit b3f8cf1

Please sign in to comment.