-
Couldn't load subscription status.
- Fork 193
feat: Implement email OTP authentication #2414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
HarshMN2345
wants to merge
6
commits into
main
Choose a base branch
from
feat-SER-191-Implement-Email-OTP-Flow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
efed2cc
feat: Implement email OTP authentication
HarshMN2345 dde26a0
Merge remote-tracking branch 'origin/main' into feat-SER-191-Implemen…
HarshMN2345 32180c5
added timer to prevent abuse
HarshMN2345 fe18032
svelte 5 migartion and some fixes
HarshMN2345 89b69e1
Update src/routes/(public)/(guest)/login/+page.svelte
HarshMN2345 30bfd2b
Update src/routes/(public)/(guest)/login/+page.svelte
HarshMN2345 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| <script lang="ts"> | ||
| import { browser } from '$app/environment'; | ||
| import { onMount, onDestroy } from 'svelte'; | ||
| import { Link } from '@appwrite.io/pink-svelte'; | ||
|
|
||
| let { | ||
| storageKey, | ||
| seconds = 60, | ||
| disabled = $bindable(false), | ||
| onResend | ||
| }: { | ||
| storageKey: string; | ||
| seconds?: number; | ||
| disabled?: boolean; | ||
| onResend: () => Promise<void> | void; | ||
| } = $props(); | ||
|
|
||
| let remaining = $state(0); | ||
| let interval: ReturnType<typeof setInterval> | null = null; | ||
|
|
||
| function start(now = Date.now()) { | ||
| const end = now + seconds * 1000; | ||
| if (browser) { | ||
| localStorage.setItem(`${storageKey}:end`, String(end)); | ||
| } | ||
| tick(end); | ||
| startTick(end); | ||
| } | ||
|
|
||
| function restore() { | ||
| if (!browser) return; | ||
| const raw = localStorage.getItem(`${storageKey}:end`); | ||
| if (!raw) return; | ||
| const end = parseInt(raw); | ||
| const now = Date.now(); | ||
| const rem = Math.max(0, Math.ceil((end - now) / 1000)); | ||
| if (rem > 0) { | ||
| remaining = rem; | ||
| startTick(end); | ||
| } else { | ||
| localStorage.removeItem(`${storageKey}:end`); | ||
| remaining = 0; | ||
| } | ||
| } | ||
|
|
||
| function tick(end: number) { | ||
| const now = Date.now(); | ||
| remaining = Math.max(0, Math.ceil((end - now) / 1000)); | ||
| if (remaining === 0 && browser) { | ||
| localStorage.removeItem(`${storageKey}:end`); | ||
| } | ||
| } | ||
|
|
||
| function startTick(end: number) { | ||
| clearTick(); | ||
| interval = setInterval(() => { | ||
| tick(end); | ||
| if (remaining === 0) clearTick(); | ||
| }, 1000); | ||
| } | ||
|
|
||
| function clearTick() { | ||
| if (interval) { | ||
| clearInterval(interval); | ||
| interval = null; | ||
| } | ||
| } | ||
|
|
||
| async function handleResend() { | ||
| if (disabled || remaining > 0) return; | ||
| await onResend?.(); | ||
| start(); | ||
| } | ||
|
|
||
| onMount(restore); | ||
| onDestroy(() => clearTick()); | ||
| </script> | ||
|
|
||
| {#if remaining > 0} | ||
| Try again in {remaining}s | ||
| {:else} | ||
| <Link.Button on:click={handleResend} {disabled}>Resend code</Link.Button> | ||
| {/if} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.