|
3 | 3 | import type { ActionData, PageServerData } from './$types';
|
4 | 4 | import toast from 'svelte-french-toast';
|
5 | 5 | import { onMount } from 'svelte';
|
6 |
| - import {page} from "$app/stores"; |
7 |
| - import {invalidateAll} from "$app/navigation"; |
| 6 | + import { page } from '$app/stores'; |
| 7 | + import { invalidateAll } from '$app/navigation'; |
8 | 8 | let expireTime;
|
9 | 9 |
|
10 | 10 | export let form: ActionData;
|
|
18 | 18 | $: show = data.isAuthenticated;
|
19 | 19 |
|
20 | 20 | const logoutUser = async () => {
|
21 |
| - const response = await fetch( "/api/logout", { |
22 |
| - method: "POST", |
23 |
| - body: JSON.stringify( { email: data.user.email } ), |
| 21 | + const response = await fetch('/api/logout', { |
| 22 | + method: 'POST', |
| 23 | + body: JSON.stringify({ email: data.user.email }), |
24 | 24 | headers: {
|
25 |
| - "content-type": "application/json" |
| 25 | + 'content-type': 'application/json' |
26 | 26 | }
|
27 |
| - } ); |
| 27 | + }); |
28 | 28 | const responseData = await response.json();
|
29 | 29 | show = responseData.loggedIn;
|
30 | 30 | };
|
31 | 31 |
|
32 | 32 | const updateCookieData = async () => {
|
33 |
| - const response = await fetch( "/api/updateCookieData", { |
34 |
| - method: "POST", |
35 |
| - body: JSON.stringify( { name: 'The Ether' } ), |
| 33 | + const response = await fetch('/api/updateCookieData', { |
| 34 | + method: 'POST', |
| 35 | + body: JSON.stringify({ name: 'The Ether' }), |
36 | 36 | headers: {
|
37 |
| - "content-type": "application/json" |
| 37 | + 'content-type': 'application/json' |
38 | 38 | }
|
39 |
| - } ); |
| 39 | + }); |
40 | 40 | const responseData = await response.json();
|
41 | 41 | console.log(responseData.sessionData);
|
42 | 42 | if (responseData.success) {
|
43 |
| - toast.success(`Cookie Data is successfully updated and new session data in redis is ${responseData.sessionData}`) |
| 43 | + toast.success( |
| 44 | + `Cookie Data is successfully updated and new session data in redis is ${responseData.sessionData}` |
| 45 | + ); |
44 | 46 | } else {
|
45 |
| - toast.error(responseData.message) |
| 47 | + toast.error(responseData.message); |
46 | 48 | }
|
47 |
| - await invalidateAll() |
| 49 | + await invalidateAll(); |
48 | 50 | };
|
49 | 51 | </script>
|
50 | 52 |
|
51 | 53 | <div class="h-screen font-sans login bg-cover">
|
52 | 54 | <div class="container mx-auto h-full flex flex-1 justify-center items-center">
|
53 | 55 | <div class="w-full max-w-lg">
|
54 | 56 | {#if show}
|
55 |
| - |
56 | 57 | <div class="relative mx-auto max-w-md overflow-hidden rounded-lg bg-white shadow">
|
57 | 58 | <div>
|
58 |
| - <img src="https://images.unsplash.com/photo-1480714378408-67cf0d13bc1b?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2070&q=80" class="w-full object-cover" alt="" /> |
| 59 | + <img |
| 60 | + src="https://images.unsplash.com/photo-1480714378408-67cf0d13bc1b?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2070&q=80" |
| 61 | + class="w-full object-cover" |
| 62 | + alt="" |
| 63 | + /> |
59 | 64 | </div>
|
60 |
| - <div class="absolute inset-0 z-10 bg-gradient-to-t from-black"></div> |
| 65 | + <div class="absolute inset-0 z-10 bg-gradient-to-t from-black" /> |
61 | 66 | <div class="absolute inset-x-0 bottom-0 z-20 p-4">
|
62 |
| - <p class="mb-1 text-sm text-white text-opacity-80">{#if $page.data.user?.name} {$page.data.user.name} • {/if} <time>Session is valid for only 10 Mins</time></p> |
63 |
| - <h3 class="text-xl font-medium text-white">{#if $page.data.user?.email} {$page.data.user.email} {/if}</h3> |
64 |
| - <p class="mt-1 text-white text-opacity-80">You are testing for sveltekit redis session manager by ethercorps.</p> |
| 67 | + <p class="mb-1 text-sm text-white text-opacity-80"> |
| 68 | + {#if $page.data.user?.name} {$page.data.user.name} • {/if} |
| 69 | + <time>Session is valid for only 10 Mins</time> |
| 70 | + </p> |
| 71 | + <h3 class="text-xl font-medium text-white"> |
| 72 | + {#if $page.data.user?.email} {$page.data.user.email} {/if} |
| 73 | + </h3> |
| 74 | + <p class="mt-1 text-white text-opacity-80"> |
| 75 | + You are testing for sveltekit redis session manager by ethercorps. |
| 76 | + </p> |
65 | 77 | </div>
|
66 | 78 | </div>
|
67 | 79 | <div class="flex items-center justify-center mt-2">
|
68 |
| - <div class="inline-flex -space-x-0 divide-x divide-gray-900 overflow-hidden rounded-lg border border-gray-900 shadow-sm"> |
69 |
| - <button on:click={() => updateCookieData()} |
70 |
| - type="button" class="inline-flex items-center bg-amber-500 px-4 py-2.5 text-center text-sm font-medium text-amber-100 shadow-sm hover:bg-amber-100 hover:text-amber-900 transition easy-in-out duration-500"> |
71 |
| - <svg xmlns="http://www.w3.org/2000/svg" class="mr-2 h-4 w-4" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"> |
72 |
| - <path stroke-linecap="round" stroke-linejoin="round" d="M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0l3.181 3.183a8.25 8.25 0 0013.803-3.7M4.031 9.865a8.25 8.25 0 0113.803-3.7l3.181 3.182m0-4.991v4.99" /> |
| 80 | + <div |
| 81 | + class="inline-flex -space-x-0 divide-x divide-gray-900 overflow-hidden rounded-lg border border-gray-900 shadow-sm" |
| 82 | + > |
| 83 | + <button |
| 84 | + on:click={() => updateCookieData()} |
| 85 | + type="button" |
| 86 | + class="inline-flex items-center bg-amber-500 px-4 py-2.5 text-center text-sm font-medium text-amber-100 shadow-sm hover:bg-amber-100 hover:text-amber-900 transition easy-in-out duration-500" |
| 87 | + > |
| 88 | + <svg |
| 89 | + xmlns="http://www.w3.org/2000/svg" |
| 90 | + class="mr-2 h-4 w-4" |
| 91 | + fill="none" |
| 92 | + viewBox="0 0 24 24" |
| 93 | + stroke-width="1.5" |
| 94 | + stroke="currentColor" |
| 95 | + > |
| 96 | + <path |
| 97 | + stroke-linecap="round" |
| 98 | + stroke-linejoin="round" |
| 99 | + d="M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0l3.181 3.183a8.25 8.25 0 0013.803-3.7M4.031 9.865a8.25 8.25 0 0113.803-3.7l3.181 3.182m0-4.991v4.99" |
| 100 | + /> |
73 | 101 | </svg>
|
74 | 102 |
|
75 | 103 | Update Cookie Data
|
76 | 104 | </button>
|
77 |
| - <button on:click={() => logoutUser()} |
78 |
| - type="button" class="inline-flex items-center bg-red-500 px-4 py-2.5 text-center text-sm font-medium text-red-100 shadow-sm hover:bg-red-100 hover:text-red-900 transition easy-in-out duration-500"> |
| 105 | + <button |
| 106 | + on:click={() => logoutUser()} |
| 107 | + type="button" |
| 108 | + class="inline-flex items-center bg-red-500 px-4 py-2.5 text-center text-sm font-medium text-red-100 shadow-sm hover:bg-red-100 hover:text-red-900 transition easy-in-out duration-500" |
| 109 | + > |
79 | 110 | <svg
|
80 |
| - xmlns="http://www.w3.org/2000/svg" |
81 |
| - fill="none" |
82 |
| - viewBox="0 0 24 24" |
83 |
| - stroke-width="1.5" |
84 |
| - stroke="currentColor" |
85 |
| - class="w-6 h-6" |
| 111 | + xmlns="http://www.w3.org/2000/svg" |
| 112 | + fill="none" |
| 113 | + viewBox="0 0 24 24" |
| 114 | + stroke-width="1.5" |
| 115 | + stroke="currentColor" |
| 116 | + class="w-6 h-6" |
86 | 117 | >
|
87 | 118 | <path
|
88 |
| - stroke-linecap="round" |
89 |
| - stroke-linejoin="round" |
90 |
| - d="M15.75 9V5.25A2.25 2.25 0 0013.5 3h-6a2.25 2.25 0 00-2.25 2.25v13.5A2.25 2.25 0 007.5 21h6a2.25 2.25 0 002.25-2.25V15M12 9l-3 3m0 0l3 3m-3-3h12.75" |
| 119 | + stroke-linecap="round" |
| 120 | + stroke-linejoin="round" |
| 121 | + d="M15.75 9V5.25A2.25 2.25 0 0013.5 3h-6a2.25 2.25 0 00-2.25 2.25v13.5A2.25 2.25 0 007.5 21h6a2.25 2.25 0 002.25-2.25V15M12 9l-3 3m0 0l3 3m-3-3h12.75" |
91 | 122 | />
|
92 | 123 | </svg>
|
93 | 124 | Logout
|
|
97 | 128 | {:else}
|
98 | 129 | <div class="leading-loose">
|
99 | 130 | <form
|
100 |
| - class="max-w-sm m-4 p-10 bg-white bg-opacity-25 rounded shadow-xl" |
101 |
| - method="post" |
102 |
| - use:enhance={() => { |
| 131 | + class="max-w-sm m-4 p-10 bg-white bg-opacity-25 rounded shadow-xl" |
| 132 | + method="post" |
| 133 | + use:enhance={() => { |
103 | 134 | return async ({ result, update }) => {
|
104 |
| - await invalidateAll() |
105 |
| - }; |
| 135 | + await invalidateAll(); |
| 136 | + }; |
106 | 137 | }}
|
107 | 138 | >
|
108 | 139 | <p class="text-white font-medium text-center text-lg font-bold">
|
|
111 | 142 | <div class="">
|
112 | 143 | <label class="block text-sm text-white" for="email">E-mail</label>
|
113 | 144 | <input
|
114 |
| - class="w-full px-5 py-1 text-gray-700 bg-gray-300 rounded focus:outline-none focus:bg-white" |
115 |
| - type="email" |
116 |
| - name="email" |
117 |
| - id="email" |
118 |
| - |
119 |
| - |
120 |
| - aria-label="email" |
121 |
| - required |
| 145 | + class="w-full px-5 py-1 text-gray-700 bg-gray-300 rounded focus:outline-none focus:bg-white" |
| 146 | + type="email" |
| 147 | + name="email" |
| 148 | + id="email" |
| 149 | + |
| 150 | + |
| 151 | + aria-label="email" |
| 152 | + required |
122 | 153 | />
|
123 | 154 | </div>
|
124 | 155 | <div class="mt-2">
|
125 |
| - <label class="block text-sm text-white">Password</label> |
| 156 | + <label class="block text-sm text-white">Password</label> |
126 | 157 | <input
|
127 |
| - class="w-full px-5 py-1 text-gray-700 bg-gray-300 rounded focus:outline-none focus:bg-white" |
128 |
| - value="Shivam@Meena" |
129 |
| - type="password" |
130 |
| - name="password" |
131 |
| - id="password" |
132 |
| - placeholder="Shivam@Meena" |
133 |
| - arial-label="password" |
134 |
| - required |
| 158 | + class="w-full px-5 py-1 text-gray-700 bg-gray-300 rounded focus:outline-none focus:bg-white" |
| 159 | + value="Shivam@Meena" |
| 160 | + type="password" |
| 161 | + name="password" |
| 162 | + id="password" |
| 163 | + placeholder="Shivam@Meena" |
| 164 | + arial-label="password" |
| 165 | + required |
135 | 166 | />
|
136 | 167 | </div>
|
137 | 168 |
|
138 | 169 | <div class="mt-4 items-center flex justify-center">
|
139 | 170 | <button
|
140 |
| - class="px-4 py-1 text-white font-light tracking-wider bg-gray-900 hover:bg-gray-800 rounded" |
141 |
| - type="submit">Login</button |
| 171 | + class="px-4 py-1 text-white font-light tracking-wider bg-gray-900 hover:bg-gray-800 rounded" |
| 172 | + type="submit">Login</button |
142 | 173 | >
|
143 | 174 | </div>
|
144 | 175 | </form>
|
|
151 | 182 | <style>
|
152 | 183 | .login {
|
153 | 184 | /*background: url(https://tailwindadmin.netlify.app/dist/images/login-new.jpeg);*/
|
154 |
| - background: url("http://bit.ly/2gPLxZ4"); |
| 185 | + background: url('http://bit.ly/2gPLxZ4'); |
155 | 186 | background-repeat: no-repeat;
|
156 | 187 | background-size: cover;
|
157 | 188 | }
|
|
0 commit comments